affinipay/chargeio-php

AffiniPay PHP 库

dev-master 2019-07-29 17:49 UTC

This package is not auto-updated.

Last update: 2024-09-21 03:29:57 UTC


README

AffiniPay 支付网关的 PHP 客户端库

安装

下载 PHP 客户端库

git clone git://github.com/charge-io/chargeio-php.git

要在您的应用程序中使用库,请将以下内容添加到您的 PHP 脚本中

require_once '/path/to/chargeio-php/lib/ChargeIO.php';

设置 ChargeIO 凭据

库的 API 需要凭据来访问 AffiniPay 服务器上的商户数据。您可以选择

  • 将凭据作为每个 API 调用的参数提供。

  • 使用默认凭据配置库。

    要设置默认凭据,请使用 AffiniPay_Credentials 对象调用 ChargeIO::setCredentials。AffiniPay_Credentials 对象使用公钥和密钥创建。

    ChargeIO::setCredentials(new AffiniPay_Credentials('<public_key>', '<secret_key>'));

使用 AffiniPay 托管字段创建交易令牌

在将敏感支付信息提交给 AffiniPay 之前,您必须对所有敏感支付信息进行令牌化。在您的支付表单上,使用 AffiniPay 的托管字段来保护支付数据,并调用 window.AffiniPay.HostedFields.getPaymentToken 创建一次性支付令牌。请参阅"使用托管字段创建支付表单"。然后,将支付令牌 ID POST 到您的 PHP 脚本。

进行交易

传递一个金额和从您的支付页面返回的一次性令牌 ID,以完成交易。

    $amount = $_POST['amount'];
    $token_id = $_POST['token_id'];
    $charge = ChargeIO_Charge::create(new ChargeIO_PaymentMethodReference(array('id' => $token_id)), $amount);

文档

最新的 AffiniPay 支付网关 API 文档可在 https://developers.affinipay.com/reference/api.html#PaymentGatewayAPI 查找。