dployhub/simplepay

Simplepay API支付集成库

dev-master 2016-11-23 05:26 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:31:19 UTC


README

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

安装步骤

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

    composer require Dploy/simplepay dev-master

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

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

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

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

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

     $ php artisan vendor:publish
    

这将添加config/simplepay.php文件

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

示例

请参考以下示例

	//add name space in your controller
	use Simplepay
	use Dploy\Simplepay\Models\CreateSyncPaymentRequest;

	//In controller action, add the following code

	//Get the request object, this is going to hold all your parameters
	$obj= new CreateSyncPaymentRequest();

	//add parameters
	$obj->currency = "USD";
	$obj->paymentBrand = "VISA";
	$obj->paymentType = "DB";
	$obj->amount = "92.00";
	$obj->cardNumber = "4200000000000000";
	$obj->cardHolder = "Mr. Abc";
	$obj->cardcvv = "125";
	$obj->cardExpiryMonth = "02";
	$obj->cardExpiryYear = "2019";

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

	//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

例如

	throw new SimplepayException($request);

Simplepay服务器到服务器支付API注意

注意:如果你希望在服务器到服务器上进行初始支付请求(因为它需要你收集卡数据),则你必须完全符合PCI标准。如果你不完全符合PCI标准,可以使用Simplepay.js来安全地收集支付数据。

方法

  • createToken
  • createTokenPayment
  • deleteToken
  • createSyncPayment(此方法直接进行支付)
  • createAsyncPayment(此方法初始化支付)
  • getPaymentStatus
  • createInitialRecurringPayment
  • createRepeatedRecurringPayment

支持的品牌

此库只支持以下品牌:VISA MASTER AMEX ALIPAY 中国银联

异步方法支持以下品牌:ALIPAY 中国银联

同步方法支持以下品牌: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. 获取支付状态

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

重定向购物者

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

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

注意:如果你希望在服务器到服务器上进行标记请求(因为它需要你收集卡数据),则你必须完全符合PCI标准。如果你不完全符合PCI标准,可以使用Simplepay.js标记教程来安全地收集支付数据。

方法细节

  1. createToken

创建用户信用卡标记的方法,不进行支付

* Requires:
* @param string userId
* @param string password
* @param string entityId
* @param string paymentBrand
* @param int cardNumber
* @param string cardHolder
* @param int cardExpiryMonth
* @param int cardExpiryYear
* @param int cardcvv
  1. createTokenPayment

一次性支付的方法

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @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 'createToken' method to store customer's card details (without making paymnet) or use 'createSyncPayments' 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 'createTokenPayment' with the mentioned paramteres to complete the payment procedure.
  1. deleteToken

删除已存在的用户令牌的方法:一旦存储,就可以使用registration.id来删除令牌

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param int registrationId
  1. createSyncPayment

单步支付方法,通过服务器到服务器的方式实现,并同步接收支付响应。

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param float amount
* @param string currency
* @param string paymentBrand
* @param string paymentType
* @param int cardNumber
* @param string cardHolder
* @param int cardExpiryMonth
* @param int cardExpiryYear
* @param string cardcvv
  1. createAsyncPayment

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

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param float amount
* @param string currency
* @param string paymentBrand
* @param string shopperResultUrl
* @param string paymentType

6.getPaymentStatus

请求异步和同步支付状态的支付状态的方法

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param string id
  1. createInitialRecurringPayment

创建令牌并同步支付的方法。

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param float amount
* @param string currency
* @param string paymentBrand
* @param string paymentType
* @param int cardNumber
* @param string cardHolder
* @param int cardExpiryMonth
* @param int cardExpiryYear
* @param string cardcvv
  1. createRepeatedRecurringPayment

创建令牌并同步支付的方法。

* Requires:
* @param string userId
* @param string entityId
* @param string password
* @param float amount
* @param string currency
* @param string paymentBrand
* @param string paymentType
* @param int cardNumber
* @param string cardHolder
* @param int cardExpiryMonth
* @param int cardExpiryYear
* @param string cardcvv

simplepay的工作原理:https://docs.simplepays.com/tutorials/server-to-server