PHP code example of getsafepay / safepay-php

1. Go to this page and download the library: Download getsafepay/safepay-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getsafepay / safepay-php example snippets


composer 


$response = $Safepay->payments->getToken(['amount'=>1000,'currency'=>'PKR']);

//$response['token'];
// Pass `token` to create checkout link


$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']);
}



$tracker = $_POST['tracker'];

$signature = $_POST['sig'];

if( $Safepay->verify->signature($tracker,$signature)  === true) {

	//Signature is valid
}



$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
}