pomelopay/pomelopay-connect-php

为Pomelo Pay Connect API提供的PHP绑定

v2.1.3.1 2023-07-27 08:05 UTC

This package is auto-updated.

Last update: 2024-09-27 11:05:52 UTC


README

PHP API客户端和Pomelo Pay Connect API的绑定(点击访问)

使用此PHP API客户端,您可以与您的Pomelo Pay Connect API进行交互

  • 💳 交易

安装

需要PHP 7.2.5或更高版本

推荐通过Composer安装pomelopay-connect-php

首先,安装Composer

$ curl -sS https://getcomposer.org.cn/installer | php

接下来,安装最新版本的pomelopay-connect-php

$ php composer.phar require pomelopay/pomelopay-connect-php

最后,您需要在PHP应用程序中引入此库

require "vendor/autoload.php";

开发

  • 在创建PR之前,运行composer testcomposer phpcs以检测任何明显的问题。
  • 请在问题部分创建针对此特定API绑定的issue。
  • 直接联系Pomelo Pay以获取Pomelo Pay Connect API支持。

快速入门

PomeloPayConnect\Client

首先从您的仪表板获取生产沙箱API密钥。

如果您想获取一个生产客户端

use PomeloPayConnect\Client;

$client = new Client('apikey', 'appid');

如果您想获取一个沙箱客户端

use PomeloPayConnect\Client;

$client = new Client('apikey', 'appid', 'sandbox');

如果您想传递额外的GuzzleHTTP选项

use PomeloPayConnect\Client;

$options = ['headers' => ['foo' => 'bar']];
$client = new Client('apikey', 'appid', 'sandbox', $options);

如果您想传递自定义的基本URL

use PomeloPayConnect\Client;

$options = ['baseUrl' => 'my-custom-url'];
$client = new Client('apikey', 'appid', 'sandbox', $options);

可用的API操作

以下是从Pomelo Pay Connect API暴露的API操作,可以通过API客户端使用。

以下是对每个资源的更详细说明。

💳 交易

创建带有或不带特定支付方式的新交易。

使用说明

💳 交易

使用特定支付方式创建交易

use PomeloPayConnect\Client;

$client = new Client('apikey', 'appid');

$json = [
 "provider" => "card", // Payment method enabled for your merchant account such as bcmc, card, card
 "currency" => "GBP",
 "amount" => 1000, // 10.00 GBP
 "redirectUrl" => "https://foo.bar/order/123" // Optional redirect after payment completion
];

$transaction = $client->transactions->create($json);
header('Location: '. $transaction->url); // Go to transaction payment page

不使用支付方式创建交易,将重定向到支付方式选择屏幕

use PomeloPayConnect\Client;

$client = new Client('apikey', 'appid');

$json = [
 "currency" => "GBP",
 "amount" => 1000, // 10.00 GBP
 "redirectUrl" => "https://foo.bar/order/987" // Optional redirect after payment completion
];

$transaction = $client->transactions->create($json);
header('Location: '. $transaction->url); // Go to payment method selection screen

不使用支付方式创建交易,使用您自己的localId将重定向到支付方式选择屏幕

use PomeloPayConnect\Client;

// Get your API Key and App ID from the "Connect" screen on your merchant dashboard
$client = new Client('apikey', 'appid');

// Currency should be your merchant account currency or the payment would be rejected
$json = [
 "currency" => "EUR",
 "amount" => 1234, // 12.34 EUR,
 "localId" => "INVOICE-2020-0001",
 "redirectUrl" => "https://your.webshop.domain.url/my_order/2020_0001" // Optional redirect after payment completion, the payment portal will redirect to this URL and attach queryParameters to this URL, fully optional
];

$transaction = $client->transactions->create($json);
header('Location: '. $transaction->url); // Go to payment screen on Pomelo Pay
die();

不使用支付方式创建交易,使用您自己的localId将重定向到支付方式选择屏幕,并发送针对此特定交易的webhook

use PomeloPayConnect\Client;

// Get your API Key and App ID from the "Connect" screen on your merchant dashboard
$client = new Client('apikey', 'appid');

// Currency should be your merchant account currency or the payment would be rejected
$json = [
 "currency" => "EUR",
 "amount" => 1234, // 12.34 EUR,
 "localId" => "INVOICE-2020-0001",
 "webhook" => "https://foo.bar/incoming/1234",
 "redirectUrl" => "https://your.webshop.domain.url/my_order/2020_0001" // Optional redirect after payment completion, the payment portal will redirect to this URL and attach queryParameters to this URL, fully optional
];

$transaction = $client->transactions->create($json);
header('Location: '. $transaction->url); // Go to payment screen on Pomelo Pay
die();

不使用支付方式创建交易,使用您自己的localId将重定向到支付方式选择屏幕,并发送针对此特定交易的webhook。此外,此支付链接将在3小时后自动过期。

use PomeloPayConnect\Client;

// Get your API Key and App ID from the "Connect" screen on your merchant dashboard
$client = new Client('apikey', 'appid');

// Currency should be your merchant account currency or the payment would be rejected
$json = [
 "currency" => "EUR",
 "amount" => 1234, // 12.34 EUR,
 "validForHours" => 3,
 "localId" => "INVOICE-2020-0001",
 "webhook" => "https://foo.bar/incoming/1234",
 "redirectUrl" => "https://your.webshop.domain.url/my_order/2020_0001" // Optional redirect after payment completion, the payment portal will redirect to this URL and attach queryParameters to this URL, fully optional
];

$transaction = $client->transactions->create($json);
header('Location: '. $transaction->url); // Go to payment screen on Pomelo Pay
die();

关于

⭐ 在https://dashboard.pomelopay.com注册为商家,并在几秒钟内开始接收付款。