yedpay / php-library
用于在线支付使用 Yedpay API 的无差别库
1.4.2
2024-01-18 06:24 UTC
Requires
- php: >=5.5
Requires (Dev)
- doctrine/instantiator: ~1.0.1 || ^1.4.0
- phpdocumentor/reflection-docblock: 3.2.2 || ^5.3.0
- phpunit/phpunit: ^4.8 || ^8.5 || ^9.5
- symfony/polyfill-ctype: 1.19.0 || ^1.23.0
- yoast/phpunit-polyfills: ^1.0
README
Yedpay 交易 PHP 库
描述
用于使用 Yedpay API 创建预创建交易和在线支付的 PHP 库
先决条件
为了开始使用 API,您需要获取您的个人访问令牌或 API 密钥。
安装
安装依赖项
composer require yedpay/php-library
运行测试
vendor/bin/phpunit
集成
请求方法
- 预创建
- 在线支付
- 退款
- 通过自定义 ID 退款
- 查询在线支付
结果
- 成功
- 错误
- 示例预创建交易实现
输入参数
//mandatory parameters
$accessToken = 'J84OFPAN';
$storeId = '8X4LZW2XLG9V';
$amount = 1.0;
//optional parameter: extraParam (JSON)
$extraParam = json_encode([
'customer_name' => 'Yed Pay',
'phone' => '12345678',
]);
创建客户端实例
$client = new Client(Library::STAGING, $accessToken);
(可选) 设置交易参数
//changing transaction currency (default: HKD)
$client->setCurrency(Client::INDEX_CURRENCY_HKD);
//changing alipay wallet type (default: HK)
$client->setWallet(Client::INDEX_WALLET_CN);
发送预创建请求
// general
$client->precreate($storeId, $amount);
// with extra parameters
$result = $client->precreate(
$storeId,
$amount,
json_encode($extraParam)
)->getData();
- 示例在线支付实现
输入参数
//mandatory parameters
$apiKey = 'qPOcLJsNnnI2wzJdIsRULOwC//KZa+KGrarUIs1ZZa8=';
$customId = 'test-001';
$amount = 1.0;
$currency = 1;
$notifyUrl = 'https://www.example.com/notify';
$returnUrl = 'https://www.example.com/return';
创建客户端实例
$client = new Client(Library::STAGING, $apiKey, false);
(可选) 设置交易参数
//changing transaction currency (default: HKD)
$client->setCurrency(Client::INDEX_CURRENCY_HKD);
//set transaction gateway code
$client->setGatewayCode(Client::INDEX_GATEWAY_CODE_ALIPAY_ONLINE_PC2MOBILE);
//set transaction gateway wallet type (default: HK)
$client->setWallet(Client::INDEX_WALLET_CN);
//set production name of transaction
$client->setSubject('Product');
//set expiry time of transaction
$client->setExpiryTime(900);
//set metadata of online payment
$metadata = json_encode([
'woocommerce' => '1.0',
'yedpay_for_woocommerce' => '1.0',
'wordpress' => '1.0',
]);
$client->setMetadata($metadata);
//set payment data of online payment
$paymentData = json_encode([
'first_name' => 'Yedpay',
'last_name' => 'Yedpay',
'email' => 'info@example.com',
'phone' => '12345678',
'billing_country' => 'HK',
'billing_city' => 'Hong Kong',
'billing_address1' => 'Address1',
'billing_address2' => 'Address2',
'billing_post_code' => '000000',
]);
$client->setPaymentData($paymentData);
//set checkout domain key of online payment
$client->setCheckoutDomainId('J84OFPAN');
发送在线支付请求
$client->onlinePayment($customId, $amount)->getData();
- 示例退款交易实现
输入参数
//mandatory parameters
$transactionId = 'J84OFPAN';
//optional parameter: reason (String)
$reason = 'testing';
创建客户端实例
// with accessToken
$client = new Client(Library::STAGING, $accessToken);
// with apiKey
$client = new Client(Library::STAGING, $apiKey, false);
发送退款请求
// general
$client->refund($transactionId)->getData();
// with reason
$client->refund($transactionId, $reason)->getData();
// with amount
$client->refund($transactionId, $reason, $amount)->getData();
- 示例通过自定义 ID 退款实现
输入参数
//mandatory parameters
$customId = 'J84OFPAN';
//optional parameter: reason (String)
$reason = 'testing';
创建客户端实例
// with apiKey
$client = new Client(Library::STAGING, $apiKey, false);
发送通过自定义 ID 退款请求
// general
$client->refundByCustomId($customId)->getData();
// with reason
$client->refundByCustomId($customId, $reason)->getData();
// with amount
$client->refundByCustomId($customId, $reason, $amount)->getData();
查看完整代码,请检查示例文件夹