getsafepay / safepay-php
Official PHP SDK for Safepay Checkout
Installs: 1 036
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
README
Official PHP SDK for Safepay API.
Installation
composer require getsafepay/safepay-php
Usage
Import and create a Safepay client by passing your config;
use Safepay\Safepay;
$config = [
"environment" =>'sandbox',
"apiKey" => 'sec_e9273e07a7ac',
"v1Secret" => 'a73e5dad7cd8b1e7fea2f6d93f4c8',
"webhookSecret" => '14509fdd8591a60427e'
];
$Safepay = new Safepay($config);
You can now create payments and checkout links.
Payments
$response = $Safepay->payments->getToken(['amount'=>1000,'currency'=>'PKR']);
//$response['token'];
// Pass `token` to create checkout link
Checkout
Create checkout link.
For mobile, set the source
to mobile
as opposed to custom
in the payload. You also do not need to pass a success_url
or a cancel_url
.
$link = $Safepay->checkout->create([
"token" => $response['token'],
"order_id" => 234,
"source"=>'custom',
"webhooks"=>'true',
"success_url" =>"url /success.php",
"cancel_url" => "url /cancel.php"
]);
//redirect user to url
if( $link['result'] == 'success' ) {
header('Location:'.$link['redirect']);
}
Verification
Signature verification on success page.
$tracker = $_POST['tracker'];
$signature = $_POST['sig'];
if( $Safepay->verify->signature($tracker,$signature) === true) {
//Signature is valid
}
Webhook
Signature verification of Webhook post request
$X_SFPY_SIGNATURE = @$_SERVER['HTTP_X_SFPY_SIGNATURE'];
$data = file_get_contents('php://input');
if( $Safepay->verify->webhook($data,$X_SFPY_SIGNATURE) === true) {
//Web Hook request is valid
}