getsafepay/safepay-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

getsafepay/safepay-php

最新稳定版本:v1.0.0

Composer 安装命令:

composer require getsafepay/safepay-php

包简介

Official PHP SDK for Safepay Checkout

README 文档

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
}

统计信息

  • 总下载量: 1.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-31