Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
examples and rc
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiodionisi committed Jan 17, 2019
1 parent 895e48c commit 37791bc
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 287 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/examples/authentication.json
composer.lock
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Satispay <business@satispay.com>
Copyright (c) 2018-2019 Satispay <business@satispay.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
50 changes: 14 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ composer require satispay/online-api-php-sdk
If you do not wish to use Composer, import the `init.php` file.

```php
require_once('/path/init.php');
require_once("/path/init.php");
```

## Documentation
Expand All @@ -25,55 +25,33 @@ Use the activation token with the `authenticateWithToken` function to generate a

Save the keys in your database or in a **safe place** not accesibile from your website.
```php
// Initialize an empty Api
$api = new \SatispayOnline\Api();

// Authenticate and generate the keys
$api->authenticateWithToken("XXXXXX");
\SatispayOnline\Api::authenticateWithToken("XXXXXX");

// Export the keys
$publicKey = $api->getPublicKey();
$privateKey = $api->getPrivateKey();
$keyId = $api->getKeyId();
$serverPublicKey = $api->getServerPublicKey();
// Export keys
$publicKey = \SatispayOnline\Api::getPublicKey();
$privateKey = \SatispayOnline\Api::getPrivateKey();
$keyId = \SatispayOnline\Api::getKeyId();
```

To reuse the keys after authentication, pass them as an argument in the `\SatispayOnline\Api` constructor.
Reuse the keys after authentication.
```php
// Keys variables
$publicKey = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhk...";
$privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg...";
$keyId = "ldg9sbq283og7ua1abpj989kbbm2g60us6f18c1sciq...";
$serverPublicKey = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhk...";

// Pass keys to Api constructor
$api = new \SatispayOnline\Api(array(
"publicKey" => $publicKey,
"privateKey" => $privateKey,
"keyId" => $keyId,
"serverPublicKey" => $serverPublicKey
));
// Set keys
\SatispayOnline\Api::setPublicKey($publicKey);
\SatispayOnline\Api::setPrivateKey($privateKey);
\SatispayOnline\Api::setKeyId($keyId);

// Test the authentication
try {
$api->testAuthentication();
} catch(\Exception $ex) {
echo $ex->message;
exit;
}
\SatispayOnline\Api::testAuthentication();
```

## Enable Sandbox
To enable sandbox pass `sandbox` with value `true` as an argument in the `\SatispayOnline\Api` constructor.
```php
// Pass sandbox = true to Api constructor
$api = new \SatispayOnline\Api(array(
"sandbox" => true
// Other arguments
));
```

You can also use the `setSandbox` function.
To enable sandbox use `setSandbox` with value `true`.
```php
$api->setSandbox(true);
\SatispayOnline\Api::setSandbox(true);
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"php",
"sdk"
],
"homepage": "http://satispay.com",
"homepage": "https://www.satispay.com",
"version": "2.0.0",
"authors": [
{
"name": "Satispay",
"homepage": "http://satispay.com"
"homepage": "https://www.satispay.com"
}
],
"require": {
Expand Down
17 changes: 17 additions & 0 deletions examples/auth-with-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

\SatispayOnline\Api::authenticateWithToken("L88B34");

$publicKey = \SatispayOnline\Api::getPublicKey();
$privateKey = \SatispayOnline\Api::getPrivateKey();
$keyId = \SatispayOnline\Api::getKeyId();

file_put_contents("authentication.json", json_encode(array(
"public_key" => $publicKey,
"private_key" => $privateKey,
"key_id" => $keyId
), JSON_PRETTY_PRINT));
19 changes: 19 additions & 0 deletions examples/create-charge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$charge = \SatispayOnline\Charge::create(array(
"user_id" => "c7cfe7ea-ad2b-40f6-8098-253bc701a2b3",
"amount" => 199,
"currency" => "EUR"
));

var_dump($charge);
21 changes: 21 additions & 0 deletions examples/create-checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$checkout = \SatispayOnline\Checkout::create(array(
"phone_number" => "",
"amount_unit" => 199,
"currency" => "EUR",
"description" => "",
"redirect_url" => ""
));

var_dump($checkout);
19 changes: 19 additions & 0 deletions examples/create-refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$refund = \SatispayOnline\Refund::create(array(
"charge_id" => "6ae4cfd9-5f79-441e-9a94-3dd157708351",
"amount" => 199,
"currency" => "EUR"
));

var_dump($refund);
17 changes: 17 additions & 0 deletions examples/create-user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$user = \SatispayOnline\User::create(array(
"phone_number" => "+390000000000"
));

var_dump($user);
15 changes: 15 additions & 0 deletions examples/get-charge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$charge = \SatispayOnline\Charge::get("6ae4cfd9-5f79-441e-9a94-3dd157708351");

var_dump($charge);
15 changes: 15 additions & 0 deletions examples/get-charges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$charges = \SatispayOnline\Charge::all();

var_dump($charges);
15 changes: 15 additions & 0 deletions examples/get-refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$refund = \SatispayOnline\Refund::get("f37af3e1-a25c-4924-a8ea-e88a7bbbaea4");

var_dump($refund);
15 changes: 15 additions & 0 deletions examples/get-refunds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$refunds = \SatispayOnline\Refund::all();

var_dump($refunds);
15 changes: 15 additions & 0 deletions examples/get-user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$user = \SatispayOnline\User::get("c7cfe7ea-ad2b-40f6-8098-253bc701a2b3");

var_dump($user);
15 changes: 15 additions & 0 deletions examples/get-users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$users = \SatispayOnline\User::all();

var_dump($users);
13 changes: 13 additions & 0 deletions examples/test-auth-with-bearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setSecurityBearer($authData->security_bearer);

$result = \SatispayOnline\Api::testAuthentication();

var_dump($result);
15 changes: 15 additions & 0 deletions examples/test-auth-with-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$result = \SatispayOnline\Api::testAuthentication();

var_dump($result);
25 changes: 25 additions & 0 deletions examples/update-charge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

require_once("../init.php");

\SatispayOnline\Api::setSandbox(true);

$authData = json_decode(file_get_contents("authentication.json"));

\SatispayOnline\Api::setPublicKey($authData->public_key);
\SatispayOnline\Api::setPrivateKey($authData->private_key);
\SatispayOnline\Api::setKeyId($authData->key_id);

$charge = \SatispayOnline\Charge::create(array(
"user_id" => "c7cfe7ea-ad2b-40f6-8098-253bc701a2b3",
"amount" => 199,
"currency" => "EUR"
));

var_dump($charge);

$ucharge = \SatispayOnline\Charge::update($charge->id, array(
"charge_state" => "CANCELED"
));

var_dump($ucharge);
10 changes: 5 additions & 5 deletions init.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
require_once(dirname(__FILE__) . "/lib/Api.php");

require_once(dirname(__FILE__) . "/lib/Amounts.php");
require_once(dirname(__FILE__) . "/lib/Charges.php");
require_once(dirname(__FILE__) . "/lib/Checkouts.php");
require_once(dirname(__FILE__) . "/lib/Refunds.php");
require_once(dirname(__FILE__) . "/lib/Amount.php");
require_once(dirname(__FILE__) . "/lib/Charge.php");
require_once(dirname(__FILE__) . "/lib/Checkout.php");
require_once(dirname(__FILE__) . "/lib/Refund.php");
require_once(dirname(__FILE__) . "/lib/Request.php");
require_once(dirname(__FILE__) . "/lib/Users.php");
require_once(dirname(__FILE__) . "/lib/User.php");
19 changes: 19 additions & 0 deletions lib/Amount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace SatispayOnline;

class Amount {
/**
* Get amounts
* @param array $options Options
*/
public static function all($options = array()) {
$queryString = "";
if (!empty($options)) {
$queryString .= "?";
$queryString .= http_build_query($options);
}
return Request::get("/online/v1/amounts$queryString", array(
"sign" => true
));
}
}
Loading

0 comments on commit 37791bc

Please sign in to comment.