masterzero/simplepay

一个用于支付的simplepay库

dev-master 2018-05-04 09:53 UTC

This package is not auto-updated.

Last update: 2024-09-22 04:24:31 UTC


README

这是一个简单的Laravel 5服务器到服务器的Simplepay支付网关库。

安装步骤

  1. 在您的终端中使用以下命令安装此库。 (当前库处于开发模式)

    composer require mansa/simplepay dev-master

  2. 更新config/app.php中的提供者

     'providers' => [
         // ...
         Mansa\Simplepay\SimplepayServiceProvider::class,
         Mansa\Simplepay\SimplepayRequestServiceProvider::class,
     ]
    
  3. 更新config/app.php中的别名

     'aliases' => [
         // ...
         'Simplepay' => Mansa\Simplepay\Facade\Simplepay::class,
     'SimplepayRequest'=>Mansa\Simplepay\Facade\SimplepayRequest::class,
     ]
    
  4. 在您的项目根目录的composer.json中添加以下行

      "autoload": {
             "psr-4": {
     	        ......
     	        ......
                 "Mansa\\Simplepay\\": "src/"
             }
         },
    
  5. 在您的终端中使用composer命令

     composer dumpautoload
    
  6. 要使用自己的设置,请发布配置。

     $ php artisan vendor:publish
    

这将添加config/simplepay.php文件

注意:请确保您的系统中已安装curl。

示例

请参考以下示例

	//add name space in your controller
	use Simplepay;
	use SimplepayRequest;

	//In controller action, add the following code

	//Get the request object, this is going to hold all your parameters
	$requestArr = array(
	      	'currency'=>'USD',
		'card.number'=>4200000000000000,
		'card.expiryMonth'=>'02',
		'card.expiryYear'=>'2019',
		'card.holder'=>"Mr. ABC",
		'card.cvv'=>123,
		'paymentBrand'=>'VISA',//'CHINAUNIONPAY',
		'amount'=>'10.00',
		'paymentType'=>'DB',
	      );
	
	//call SimplepayRequest and set the parameters
	SimplepayRequest::setParams($requestArr);
    	$getParams =  SimplepayRequest::getParams();

	//Now we are ready to make our call, this is going to make your direct payment in simplepay gateway
	 $result = Simplepay::requestSyncPayment($getParams);

	//Here you can check the response returned by simplepay gateway
	var_dump($result);

结果

如果所有参数都正确,则API将返回以下数组结构。请注意,在测试模式下,消息将是“在集成商测试模式下成功处理请求”

	array(6) {
	  ["isSuccess"]=>
	  bool(true)
	  ["message"]=>
	  string(68) "Request successfully processed"
	  ["code"]=>
	  string(11) "000.100.110"
	  ["crud"]=>
	  string(579) "{"id":"8a82944a571dace401574ca1d2ec4290","paymentType":"DB","paymentBrand":"VISA","amount":"92.00","currency":"USD","descriptor":"5486.6167.4658 OPP_Channel ","result":{"code":"000.100.110","description":"Request successfully processed in 'Merchant in Integrator Test Mode'"},"card":{"bin":"420000","last4Digits":"0000","expiryMonth":"02","expiryYear":"2019"},"risk":{"score":"100"},"buildNumber":"34cf17be72dfb23fff3ba15de38c948bcddfcca6@2016-09-20 10:54:39 +0000","timestamp":"2016-09-21 12:04:16+0000","ndc":"8a8294184e542a5c014e691d33f808c8_b86252609caf47ce8bd7ab309dd425b1"}"
	  ["registrationId"]=>
	  bool(false)
	  ["id"]=>
	  string(32) "8a82944a571dace401574ca1d2ec4290"
	}

如果发生错误或缺少参数,则使用SimplepayException类抛出错误

  • SimplepayException

例如

	throw new SimplepayException("No params found");

Simplepay服务器到服务器支付API说明

注意:如果您想执行服务器到服务器的初始支付请求(因为它需要收集卡数据),则必须完全遵守PCI规范。如果不完全符合PCI规范,可以使用Simplepay.js安全地收集支付数据。

方法

  • createTokenWithPayment
  • createTokenWithoutPayment
  • makeOneClickPayment
  • makeDeleteTokenRequest
  • requestSyncPayment (该方法直接进行支付)
  • requestAsyncPayment (该方法初始化支付)
  • requestPaymentStatus
  • createTokenWithInitialRecurringPayment
  • requestRecurringPaymentWithToken
  • reverseSyncPayment

支持的品牌

此库仅支持以下品牌:VISA MASTER AMEX ALIPAY CHINAUNIONPAY

异步方法支持以下品牌:ALIPAY CHINAUNIONPAY

同步方法支持以下品牌:VISA MASTER AMEX

配置文件路径

	/src/Config/simplepay.php

使用的环境变量

	SIMPLEPAY_TEST_ENDPOINT=https://test.oppwa.com/
	SIMPLEPAY_LIVE_ENDPOINT=https://oppwa.com/
	SIMPLEPAY_VERSION=v1
	SIMPLEPAY_API_ENVIRONMENT=test
	SIMPLEPAY_USER_ID = replace with your userId
	SIMPLEPAY_ENTITY_ID = replace with your entityid
	SIMPLEPAY_PASSWORD = replace with your password

同步工作流程

每个支付品牌遵循以下两种工作流程之一:异步或同步。在同步工作流程中,支付数据直接在服务器到服务器的初始支付请求中发送,并立即处理支付。

  1. 发送初始支付

异步工作流程

在异步工作流程中,发生重定向,允许账户持有人完成/验证支付。之后,账户持有人将被重定向回shopperResultUrl,可以查询支付状态。

  1. 发送初始支付
  2. 重定向购物者
  3. 获取支付状态

发送初始支付:使用[requestAsyncPayment]方法进行初始支付

重定向购物者

下一步是重定向账户持有人。为此,您必须解析初始支付响应中的redirect_url以及任何参数。如果存在参数,它们应该在重定向中为POST,否则只需直接重定向到redirect_url即可。

获取支付状态:使用[requestPaymentStatus]方法检查支付状态

注意:如果您想执行服务器到服务器的令牌化请求(因为它需要收集卡数据),则必须完全遵守PCI规范。如果不完全符合PCI规范,可以使用Simplepay.js令牌化教程安全地收集支付数据。

方法细节

  1. createTokenWithPayment:

创建令牌或注册用户的信用卡并同步进行支付的方法。响应中的"registrationId"参数用于执行各种创建定期支付的方法,并且用作获取支付状态的'id'。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentBrand
  • @param string paymentType
  • @param int card.number
  • @param string card.holder
  • @param string card.expiryMonth
  • @param int card.expiryYear
  • @param string card.cvv
  1. createTokenWithoutPayment:

创建令牌或注册用户信用卡而不进行支付的方法。响应中的“registrationId”参数用于进行各种定期支付方法,并且也用作获取支付状态的'id'。

  • 需要
  • @param string paymentBrand
  • @param int card.number
  • @param string card.holder
  • @param string card.expiryMonth
  • @param int card.expiryYear
  • @param string card.cvv
  1. makeOneClickPayment:

一键支付的方法。可以使用令牌注册方法获取'registrationId'(响应变量'registrationId'可以用来获取)。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentType
  • @param int registrationId

一键支付:此方法需要3个步骤:1. 验证用户 2. 显示结账 3. 发送支付

Step 1: Authenticate user
You will need a method to authenticate the customer against your records in order to obtain their respective registration.id (token) associated with their account.  This can be achieved by asking the customer to log in for example, however you may find other ways that are applicable to your system.

The information that you might want to store, per customer, in order to execute a One-Click payment includes:

    registrationId (token): You can use 'createTokenWithOutPayment' method to store customer's card details (without making paymnet) or use 'makeSyncPayments' method, and set createRegistration to true, to get the registrationId for user's card.
    account brand: brand of customer's card 
    last four digits of account number
    expiry date (if applicable)

Step 2: Show Checkout Form:
Create a form, to show user's all stored cards (You need to create form similar to this  https://docs.simplepays.com/sites/default/files/one-click-checkout.png) and show the list of all the cards you have stored. You can take example of html from page "https://docs.simplepays.com/tutorials/server-to-server/one-click-payment-guide".

Step 3: Send Payment
 	When user click on pay button use method 'makeOneClickPayment' with the mentioned paramteres to complete the payment procedure.
  1. makeDeleteTokenRequest:

用于删除已存储的用户令牌的调用方法。一旦存储,可以使用'registrationId'删除令牌。可以使用令牌注册方法获取'registrationId'(响应变量'registrationId'可以用来获取)。

  • 需要
  • @param int registrationId
  1. requestSyncPayment:

使用服务器到服务器单步支付并同步接收支付响应的方法。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentBrand
  • @param string paymentType
  • @param int card.number
  • @param string card.holder
  • @param string card.expiryMonth
  • @param int card.expiryYear
  • @param string card.cvv
  1. requestAsyncPayment:

请求通过异步方法发送初始支付请求的方法。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentBrand
  • @param string shopperResultUrl
  • @param string paymentType

7.requestPaymentStatus

请求支付状态的方法。可以使用令牌注册方法获取'id'(可以使用响应变量'id'或'registration')。

  • 需要
  • @param string id
  1. createTokenWithInitialRecurringPayment:

创建令牌或注册用户信用卡并同步支付的方法。此方法还初始化定期支付。此API将在"id"数组变量中返回令牌id。您需要存储此"id"以供将来参考,以了解您的支付状态或删除令牌时将使用此令牌id。响应中的"registrationId"参数用于各种定期支付方法,并且也用作获取支付状态的'id'。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentBrand
  • @param string paymentType
  • @param int card.number
  • @param string card.holder
  • @param string card.expiryMonth
  • @param int card.expiryYear
  • @param string card.cvv
  1. requestRecurringPaymentWithToken:

创建令牌并同步支付的方法。此方法也用于重复的定期支付。

  • 需要
  • @param float amount
  • @param string currency
  • @param string paymentBrand
  • @param string paymentType
  • @param int card.number
  • @param string card.holder
  • @param string card.expiryMonth
  • @param int card.expiryYear
  • @param string card.cvv
  • @param string registrationId
  1. reverseSyncPayment:

撤销支付的方法

  • 需要
  • @param string paymentType (RV | RF)
  • @param string id

simplepay是如何工作的: https://docs.simplepays.com/tutorials/server-to-server