Skip to content

Commit

Permalink
Add update method on PreAuthorizedPaymentToken, fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleCoppola committed Oct 17, 2024
1 parent bfa3c9f commit 3f9c4e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
23 changes: 23 additions & 0 deletions examples/update-pre-authorized-payment-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

\SatispayGBusiness\Api::setSandbox(true);

$authData = json_decode(file_get_contents(__DIR__ . '/authentication.json'));

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

$preAuthorizedPaymentToken = \SatispayGBusiness\PreAuthorizedPaymentToken::create([
'reason' => 'Monthly Payments'
]);

var_dump($preAuthorizedPaymentToken);

$updatePreAuthorizedPaymentToken = \SatispayGBusiness\PreAuthorizedPaymentToken::update($preAuthorizedPaymentToken->id, [
'status' => 'CANCELED'
]);

var_dump($updatePreAuthorizedPaymentToken);
28 changes: 24 additions & 4 deletions src/PreAuthorizedPaymentToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class PreAuthorizedPaymentToken {
private static $apiPath = '/g_business/v1/pre_authorized_payment_tokens';

/**
* Create pre authorized payment token.
*
* Create a pre authorized payment token.
*
* @param array $body
* @param array $headers The format is: [header => value]
*/
Expand All @@ -25,8 +25,8 @@ public static function create($body, $headers = [])
}

/**
* Get pre authorized payment token.
*
* Get a pre authorized payment token.
*
* @param string $id
*/
public static function get($id, $headers = [])
Expand All @@ -40,4 +40,24 @@ public static function get($id, $headers = [])
]
);
}

/**
* Update a pre authorized payment token.
*
* @param string $id
* @param array $body
* @param array $headers The format is: [header => value]
*/
public static function update($id, $body, $headers = [])
{
return
Request::put(
self::$apiPath. '/' . $id,
[
'headers' => $headers,
'body' => $body,
'sign' => true
]
);
}
}

0 comments on commit 3f9c4e7

Please sign in to comment.