fecmall 集成 braintreepayments 信用卡收款方式(php Yii2框架)服务端(server)部分

Fecmall Braintree · Fecmall · 于 4年前 发布 · 1740 次阅读

fecmall 集成 braintreepayments 信用卡收款方式(php Yii2框架)服务端(server)部分

php要求

https://developers.braintreepayments.com/start/hello-server/php

>The Braintree PHP SDK requires PHP version 7.2.0 or higher and the PHP cURL extension.

php版本7.2+, 以及需要php curl扩展

php sdk下载地址:https://developers.braintreepayments.com/client_libraries/php/braintree-php-4.5.0.tgz

Version: 4.5.0
SHA256: db1a7572944a221b2d661aaa1f9276d2a9b44ccb306589456ec8a6ce489f2e99

配置环境初始化

1.沙盒环境

$gateway = new Braintree_Gateway([
    'environment' => 'sandbox',
    'merchantId' => 'use_your_merchant_id',
    'publicKey' => 'use_your_public_key',
    'privateKey' => 'use_your_private_key'
]);

2.正式环境

如果在正式环境注册账户,获取api信息: https://developers.braintreepayments.com/start/go-live/php

$gateway = new Braintree_Gateway([
    'environment' => 'production',
    'merchantId' => 'use_your_merchant_id',
    'publicKey' => 'use_your_public_key',
    'privateKey' => 'use_your_private_key'
]);

生成client token

生成客户令牌 您的服务器负责生成客户端令牌,其中包含客户端初始化客户端SDK与Braintree进行通信所需的所有授权和配置信息。 生成客户令牌时包含customerId可使回头客从以前使用的付款方式选项中进行选择,从而改善了多次结帐时的用户体验。

$clientToken = $gateway->clientToken()->generate([
    "customerId" => $aCustomerId
]);

If the customer can't be found, it will return a validation error.

https://developers.braintreepayments.com/reference/general/validation-errors/all/php#code-92804

发送client token到客户端

echo($clientToken = $gateway->clientToken()->generate());

从客户端获取 payment method nonce

$nonceFromTheClient = $_POST["payment_method_nonce"]
/* Use payment method nonce here */

创建交易Create a transaction

$result = $gateway->transaction()->sale([
  'amount' => '10.00',
  'paymentMethodNonce' => $nonceFromTheClient,
  'options' => [
    'submitForSettlement' => True
  ]
]);

The sale call returns a Transaction Result Object which contains the transaction and information about the request.

https://developers.braintreepayments.com/reference/response/transaction/php#result-object

测试您的整合Test your integration

https://developers.braintreepayments.com/reference/general/testing/php

上线

https://developers.braintreepayments.com/start/go-live/php

共收到 1 条回复
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics