Aggreg82r pay 包

v1.0.0 2022-02-25 23:52 UTC

This package is auto-updated.

Last update: 2024-08-27 11:32:54 UTC


README

PHP SDK,用于调用 Aggreg82r.com 的结账方法

要求

  • cURL
  • PHP >7.3

安装

composer require aggreg82r/pay

使用

  1. 创建您的表单
<form action="https://aggreg82r.com/customer/checkout" method="post">
    <input type="hidden" name="payment_gateway" value="stripe">
    <input type="hidden" name="recurring" value="false">
    <input type="hidden" name="reference" value="your-reference-string">
    <input type="hidden" name="name" value="Your total cart amount from example.com">
    <input type="hidden" value="amount" name="500.45">
    <input type="hidden" name="currency" value="php">
    <button type="submit" class="btn btn-sm">Pay with Stripe</button>
</form>

必填字段

  • payment_gateway (字符串) - 目标支付网关
  • recurring (布尔值) - 如果这是一次周期性支付
  • reference (字符串) - 您本次交易的参考代码,这对于在系统中映射出执行此交易的客户非常重要
  • name (字符串) - 在结账表单中选择支付网关的描述
  • amount (字符串) - 总金额
  • currency (字符串) - 欲向客户收取的货币
  1. 获取表单的POST数据并进行 CHECKOUT
// Get the form POST data
$postData = $request->all(); // Important: Sanitize your data

// Initialize your checkout
$checkout = new \Aggreg82r\Pay\Checkout(
    'https://api.aggreg82r.com',
    '30aab829-ee2f-49c0-be87-a2149b382c7e', // API KEY
    '4c3e523d-1f78-4a97-8535-49e36763d0f5' // API SECRET
);

// get your api key and secret in https://aggreg82r.com 

$checkout->now($postData);
// This will redirect to the intended payment gateway checkout page
  1. 一旦您的客户填写了他们的信用卡详细信息,它将返回到您在 https://aggreg82r.com 凭证仪表板上定义的 success_url

不是PHP?没问题。试试curl

  1. 您的后端应该首先请求令牌,并将其保存以在第二步中使用。
curl --request POST \
  --url https://api.aggreg82r.com/customer/auth \
  --header 'Content-Type: application/json' \
  --data '{
        "api_key": "<YOUR-API-KEY>",
        "api_secret": "<YOUR-API-SECRET>",
        "grant_type": "client_credentials"
    }'
  1. 您上面的HTML表单应该提交到您的后端。然后,一旦您从前端收集了数据,将其提交到 aggreg82r.com
curl --request POST \
  --url https://api.aggreg82r.com/customer/checkout \
  --header 'Authorization: Bearer <TOKEN-FROM-ABOVE-REQUEST>' \
  --header 'Content-Type: application/json' \
  --data '{
        "payment_gateway": "stripe",
        "recurring": "false",
        "reference": "your-reference-string",
        "name": "Your total cart amount from example.com",
        "amount": "500.45",
        "currency": "USD"
    }'
  1. 完成。

这将重定向到客户的目标支付网关,以便他们输入信用卡号码。一旦他们完成,他们将重定向回您在 https://aggreg82r.com 凭证仪表板上设置的 success_url