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

Commit

Permalink
refunds
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiodionisi committed May 4, 2017
1 parent 341c1d3 commit cb3389b
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,33 @@ $charge = \Satispay\Charge::update('chargeid', [
'description' => 'newdescription'
]);
```

### Refunds

#### Create a refund
Example:
```php
\Satispay\Satispay::setSecurityBearer('yoursecuritybearer');

$refund = \Satispay\Refund::create([
'charge_id' => 'chargeid',
'currency' => 'EUR',
'amount' => 1000
]);
```

#### Get a refund list
Example:
```php
\Satispay\Satispay::setSecurityBearer('yoursecuritybearer');

$refunds = \Satispay\Refund::all();
```

#### Get a refund
Example:
```php
\Satispay\Satispay::setSecurityBearer('yoursecuritybearer');

$refund = \Satispay\Refund::get('refundid');
```
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require(dirname(__FILE__) . '/lib/User.php');
require(dirname(__FILE__) . '/lib/Bearer.php');
require(dirname(__FILE__) . '/lib/Charge.php');
require(dirname(__FILE__) . '/lib/Refund.php');
85 changes: 85 additions & 0 deletions lib/Refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
namespace Satispay;

use Satispay\Satispay;

class Refund {
public static function create($params = null) {
$result = Satispay::request('/online/v1/refunds', 'POST', $params);
$body = $result['body'];
if (!empty($body->code)) {
switch($body->code) {
case 36:
throw new \Exception('Body validation error');
break;
case 45:
throw new \Exception('Try to create a refund for a Charge not owned by user');
break;
case 52:
throw new \Exception('Beneficiary validation');
break;
}
}
return $body;
}

public static function all($params = null) {
$queryString = '';
if (!empty($params))
$queryString = http_build_query($params);
$result = Satispay::request('/online/v1/refunds?'.$queryString);
$body = $result['body'];
if (!empty($body->code)) {
switch($body->code) {
case 45:
throw new \Exception('Try to get a refund of another shop');
break;
case 52:
throw new \Exception('Beneficiary validation');
break;
}
}
return $body;
}

public static function get($id) {
$result = Satispay::request('/online/v1/refunds/'.$id);
$body = $result['body'];
if (!empty($body->code)) {
switch($body->code) {
case 41:
throw new \Exception('Refund does not exist');
break;
case 45:
throw new \Exception('Try to get a refund of another shop');
break;
case 52:
throw new \Exception('Shop validation error');
break;
}
}
return $body;
}

public static function update($id, $params = null) {
$result = Satispay::request('/online/v1/refunds/'.$id, 'PUT', $params);
$body = $result['body'];
if (!empty($body->code)) {
switch($body->code) {
case 45:
throw new \Exception('Try to update a refund of another user');
break;
case 52:
throw new \Exception('Beneficiary validation');
break;
case 36:
throw new \Exception('Body validation error');
break;
case 41:
throw new \Exception('Refund don’t exist');
break;
}
}
return $body;
}
}

0 comments on commit cb3389b

Please sign in to comment.