|
1 | 1 | # multisafepay-php
|
2 |
| -An unofficial wrapper for the MultiSafePay API. |
| 2 | +A wrapper for the MultiSafePay API. |
| 3 | + |
| 4 | +## Installation |
| 5 | + |
| 6 | +``` |
| 7 | +composer require whitecube/multisafepay-php |
| 8 | +``` |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +You must specify two things before beginning to use the API: |
| 13 | +- The application environment (accepted values are `production` or `test`) |
| 14 | +- Your MultiSafepay API key |
| 15 | + |
| 16 | +```php |
| 17 | +$client = new Whitecube\MultiSafepay\Client('production', 'your-api-key'); |
| 18 | + |
| 19 | +// Example: Get an existing order |
| 20 | +$order = $client->orders()->show('order-id'); |
| 21 | +``` |
| 22 | + |
| 23 | +### Orders |
| 24 | + |
| 25 | +The Orders API lives under the `orders` method on the client. |
| 26 | +```php |
| 27 | +$client->orders()->... |
| 28 | +``` |
| 29 | + |
| 30 | +#### Creating orders |
| 31 | +[See official docs.](https://docs.multisafepay.com/api/#create-an-order) |
| 32 | +Orders are represented by PHP Objects but can be submitted as regular associative arrays. |
| 33 | + |
| 34 | +```php |
| 35 | +use Whitecube\MultiSafepay\Entities\Order; |
| 36 | + |
| 37 | +$order = new Order('my-order-id') |
| 38 | + ->type('redirect') |
| 39 | + ->amount(20) |
| 40 | + ->currency('EUR') |
| 41 | + ->description('2 movie tickets') |
| 42 | + ->paymentOptions([ |
| 43 | + 'notification_url' => 'http://www.example.com/client/notification?type=notification', |
| 44 | + 'redirect_url' => 'http://www.example.com/client/notification?type=redirect', |
| 45 | + 'cancel_url' => 'http://www.example.com/client/notification?type=cancel', |
| 46 | + 'close_window' => '' |
| 47 | + ]); |
| 48 | + |
| 49 | +$client->orders()->create($order); |
| 50 | + |
| 51 | +// Or as an associative array |
| 52 | + |
| 53 | +$client->orders()->create([ |
| 54 | + 'order_id' => 'my-order-id', |
| 55 | + 'type' => 'redirect', |
| 56 | + 'amount' => 20, |
| 57 | + 'currency' => 'EUR', |
| 58 | + 'description' => '2 movie tickets', |
| 59 | + 'payment_options' => [ |
| 60 | + 'notification_url' => 'http://www.example.com/client/notification?type=notification', |
| 61 | + 'redirect_url' => 'http://www.example.com/client/notification?type=redirect', |
| 62 | + 'cancel_url' => 'http://www.example.com/client/notification?type=cancel', |
| 63 | + 'close_window' => '' |
| 64 | + ] |
| 65 | +]); |
| 66 | + |
| 67 | +``` |
| 68 | + |
| 69 | +#### Getting orders |
| 70 | +[See official docs.](https://docs.multisafepay.com/api/#retrieve-an-order) |
| 71 | +Fetch an existing order's information |
| 72 | + |
| 73 | +```php |
| 74 | +$client->orders()->fetch('order-id'); |
| 75 | +``` |
| 76 | + |
| 77 | +#### Updating orders |
| 78 | +[See official docs.](https://docs.multisafepay.com/api/#update-an-order) |
| 79 | + |
| 80 | +```php |
| 81 | +$client->orders()->update('order-id', [ |
| 82 | + 'status' => 'completed', |
| 83 | + //... |
| 84 | +]); |
| 85 | +``` |
0 commit comments