<?phpusePlutu\Services\PlutuTlync;$amount =5.0; // amount in float format$invoiceNo ='inv-12345'; // invoice number$returnUrl = 'https://example.com/return/handler'; // the url to handle the return from plutu after payment completed from T-Lync
$callbackUrl = 'https://example.com/callback/handler'; // the url to handle the callback trgigger from plutu after payment completed from T-Lync
try { $api =newPlutuTlync; $api->setCredentials('api_key','access_token','secret_key'); $apiResponse = $api->confirm($amount, $invoiceNo, $returnUrl, $callbackUrl);if ($apiResponse->getOriginalResponse()->isSuccessful()) {// Redirect URL for Plutu and T-Lync checkout page $redirectUrl = $apiResponse->getRedirectUrl();// You should rediect the customer to payment checkout page// header("location: " . $redirectUrl); } elseif ($apiResponse->getOriginalResponse()->hasError()) {// Possible errors from Plutu API// @see https://docs.plutu.ly/api-documentation/errors Plutu API Error Documentation $errorCode = $apiResponse->getOriginalResponse()->getErrorCode(); $errorMessage = $apiResponse->getOriginalResponse()->getErrorMessage(); $statusCode = $apiResponse->getOriginalResponse()->getStatusCode(); $responseData = $apiResponse->getOriginalResponse()->getBody(); }// Handle exceptions that may be thrown during the execution of the code// The following are the expected exceptions that may be thrown:// Check the "Handle Exceptions and Errors" section for more details// // InvalidAccessTokenException, InvalidApiKeyException, InvalidSecretKeyException,// InvalidAmountException, InvalidInvoiceNoException, InvalidReturnUrlException, InvalidCallbackUrlException} catch (\Exception $e) { $exception = $e->getMessage();}
Check out the example Confirm (Pay) in the Plutu PHP Examples document on GitHub.
Callback handler
The callback will be received from Plutu when the transaction is completed. This gives a Merchant better control of how the transaction is processed on the Merchant's side. This is useful e.g. when you want to mark an order as paid, update your shop's inventory, or add appropriate records to Merchant’s internal accounting system.
Callback parameters:
The callback is called with HTTP POST as JSON
Return handler
Once the payment has been completed client can be redirected to the merchant-provided return URL.
Return parameters:
The callback is called with HTTP GET and with the same query string parameters as in the redirect
SHA-256 HMAC is calculated as follows:
The SHA-256 HMAC calculation includes all response parameters and key-value pairs except the “hashed” parameter.
Create an SHA-256 HMAC of the resultant string using the secret key created in the Plutu account and convert it to uppercase and compare it with the “hashed” parameter received in the callback or return handler.