mansa/simplepay

一个简单的支付库

dev-master 2016-09-28 15:22 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:58:47 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

支持的品牌

此库仅支持以下品牌: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

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