idnatiya / xendit-php
Xendit API 的 PHP 客户端
Requires
- php: >=7.2.0
- ext-json: *
- guzzlehttp/guzzle: >=6.0
Requires (Dev)
- phpunit/phpunit: ^8.5.13
- squizlabs/php_codesniffer: ~3.5
- vlucas/phpdotenv: ^4.1
This package is auto-updated.
Last update: 2024-09-06 07:11:14 UTC
README
此库是 Xendit API 的抽象,用于从使用 PHP 编写的应用程序中进行访问。
- 文档
- 安装
- 用法
- 方法签名和示例
- 异常
- 贡献
文档
有关 API 文档,请参阅 Xendit API 参考。
安装
使用以下命令通过composer安装xendit-php-clients
composer require idnatiya/xendit-php
或者在您的composer.json
文件中手动添加。
从v1.4.0更新到v2.0.0
要使用composer更新xendit-php-clients,请使用以下命令
composer update idnatiya/xendit-php
有关迁移信息,请参阅MIGRATE.md
用法
使用从Xendit仪表板获取的账户密钥配置包。
Xendit::setApiKey('secretKey');
有关更多详细信息,请参阅示例代码
使用自定义HTTP客户端
可以像这样注入实现HttpClientInterface的自定义HTTP客户端
Xendit::setHttpClient($client);
请参阅自定义HTTP客户端示例以获取实现参考。
方法签名和示例
余额
获取余额
$params = array( 'for-user-id' => '<sub account user id>' //The sub-account user-id that you want to make this transaction for (Optional). ); \Xendit\Balance::getBalance(string $account_type, array $params);
使用示例
$getBalance = \Xendit\Balance::getBalance('CASH'); var_dump($getBalance);
支付渠道
获取支付渠道
GetPaymentChannels处于维护模式
。端点上的现有行为将继续按以前的方式工作,但返回结果中将缺少新通道。
\Xendit\PaymentChannels::list();
使用示例
$getPaymentChannels = \Xendit\PaymentChannels::list(); var_dump($getPaymentChannels);
卡
创建费用
\Xendit\Cards::create(array $params);
使用示例
$params = [ 'token_id' => '5e2e8231d97c174c58bcf644', 'external_id' => 'card_' . time(), 'authentication_id' => '5e2e8658bae82e4d54d764c0', 'amount' => 100000, 'card_cvn' => '123', 'capture' => false ]; $createCharge = \Xendit\Cards::create($params); var_dump($createCharge);
撤销授权
\Xendit\Cards::reverseAuthorization(string $id, array $params);
使用示例
$id = 'charge-id'; $params = ['external_id' => 'ext-id']; $reverseAuth = \Xendit\Cards::reverseAuthorization( $id, $params ); var_dump($reverseAuth);
捕获费用
\Xendit\Cards::capture(string $id, array $params);
使用示例
$id = 'charge-id'; $params = ['amount' => 100000]; $captureCharge = \Xendit\Cards::capture($id, $params); var_dump($captureCharge);
获取费用
\Xendit\Cards::retrieve(string $id);
使用示例
$id = 'charge-id'; $getCharge = \Xendit\Cards::retrieve($id); var_dump($getCharge);
创建退款
\Xendit\Cards::createRefund(string $id, array $params);
使用示例
无idempotency key
$params = [ 'external_id' => 'ext-id', 'amount' => 20000 ]; $refund = \Xendit\Cards::createRefund($id, $params); var_dump($refund);
有idempotency key
$params = [ 'external_id' => 'ext-id', 'amount' => 20000, 'X-IDEMPOTENCY-KEY' => 'unique-id' ]; $refund = \Xendit\Cards::createRefund($id, $params); var_dump($refund);
创建促销
\Xendit\Promotion::create(array $params);
使用示例
$params = [ 'reference_id' => 'reference_123', 'description' => 'test promotion', 'currency' => 'IDR', 'start_time' => '2021-01-01T00:00:00.000Z', 'end_time' => '2021-01-02T00:00:00.000Z', 'promo_code' => 'testpromo', 'discount_amount' => 5000 ]; $createPromotion = \Xendit\Promotion::create($params); var_dump($createPromotion);
无卡信用卡
创建无卡信用卡支付
\Xendit\CardlessCredit::create(array $params);
使用示例
$params = [ 'cardless_credit_type' => 'KREDIVO', 'external_id' => 'test-cardless-credit-02', 'amount' => 800000, 'payment_type' => '3_months', 'items' => [ [ 'id' => '123123', 'name' => 'Phone Case', 'price' => 200000, 'type' => 'Smartphone', 'url' => 'http=>//example.com/phone/phone_case', 'quantity' => 2 ], [ 'id' => '234567', 'name' => 'Bluetooth Headset', 'price' => 400000, 'type' => 'Audio', 'url' => 'http=>//example.com/phone/bluetooth_headset', 'quantity' => 1 ] ], 'customer_details' => [ 'first_name' => 'customer first name', 'last_name' => 'customer last name', 'email' => 'customer@yourwebsite.com', 'phone' => '081513114262' ], 'shipping_address' => [ 'first_name' => 'first name', 'last_name' => 'last name', 'address' => 'Jalan Teknologi No. 12', 'city' => 'Jakarta', 'postal_code' => '12345', 'phone' => '081513114262', 'country_code' => 'IDN' ], 'redirect_url' => 'https://example.com', 'callback_url' => 'http://example.com/callback-cardless-credit' ]; $createPayment = \Xendit\CardlessCredit::create($params); var_dump($createPayment);
计算支付类型
\Xendit\CardlessCredit::calculatePaymentTypes(array $params);
使用示例
$params = [ 'cardless_credit_type' => 'KREDIVO', 'amount' => 2000000, 'items' => [ [ 'id' => '123123', 'name' => 'Phone Case', 'price' => 1000000, 'type' => 'Smartphone', 'url' => 'http://example.com/phone/phone_case', 'quantity' => 2 ] ] ]; $calculatePaymentTypes = \Xendit\CardlessCredit::calculatePaymentTypes($params); var_dump($calculatePaymentTypes);
客户
创建客户
\Xendit\Customers::createCustomer(array $params);
使用示例
$customerParams = [ 'reference_id' => '' . time(), 'given_names' => 'customer 1', 'email' => 'customer@website.com', 'mobile_number' => '+6281212345678', 'description' => 'dummy customer', 'middle_name' => 'middle', 'surname' => 'surname', 'addresses' => [ [ 'country' => 'ID', 'street_line1' => 'Jl. 123', 'street_line2' => 'Jl. 456', 'city' => 'Jakarta Selatan', 'province' => 'DKI Jakarta', 'state' => '-', 'postal_code' => '12345' ] ], 'metadata' => [ 'meta' => 'data' ] ]; $createCustomer = \Xendit\Customers::createCustomer($customerParams); var_dump($createCustomer);
通过参考 ID 获取客户
\Xendit\Customers::getCustomerByReferenceID(string $reference_id);
使用示例
$reference_id = 'ref_id'; $getCustomer = \Xendit\Customers::getCustomerByReferenceID($reference_id); var_dump($getCustomer);
直接扣款
初始化关联账户令牌化
\Xendit\DirectDebit::initializeLinkedAccountTokenization(array $params);
使用示例
$params = [ 'customer_id' => '4b7b6050-0830-440a-903b-37d527dbbaa9', 'channel_code' => 'DC_BRI', 'properties' => [ 'account_mobile_number' => '+62818555988', 'card_last_four' => '8888', 'card_expiry' => '06/24', 'account_email' => 'test.email@xendit.co' ], 'metadata' => [ 'meta' => 'data' ] ]; $initializeTokenization = \Xendit\DirectDebit::initializeLinkedAccountTokenization($params); var_dump($initializeTokenization);
验证关联账户令牌的 OTP
\Xendit\DirectDebit::validateOTPForLinkedAccount(string $linked_account_token_id, array $params);
使用示例
$params = [ 'otp_code' => '333000' ]; $validateOTPForLinkedAccount = \Xendit\DirectDebit::validateOTPForLinkedAccount( 'lat-a08fba1b-100c-445b-b788-aaeaf8215e8f', $params ); var_dump($validateOTPForLinkedAccount);
通过关联账户令牌检索可访问的账户
\Xendit\DirectDebit::retrieveAccessibleLinkedAccounts(string $linked_account_token_id);
使用示例
$retrieveAccessibleLinkedAccounts = \Xendit\DirectDebit::retrieveAccessibleLinkedAccounts( 'lat-a08fba1b-100c-445b-b788-aaeaf8215e8f' ); var_dump($retrieveAccessibleLinkedAccounts);
解绑关联账户令牌
\Xendit\DirectDebit::unbindLinkedAccountToken(string $linked_account_token_id);
使用示例
$unbindLinkedAccountToken = \Xendit\DirectDebit::unbindLinkedAccountToken( 'lat-a08fba1b-100c-445b-b788-aaeaf8215e8f' ); var_dump($unbindLinkedAccountToken);
创建支付方式
\Xendit\DirectDebit::createPaymentMethod(array $params);
使用示例
$params = [ 'customer_id' => '4b7b6050-0830-440a-903b-37d527dbbaa9', 'type' => 'DEBIT_CARD', 'properties' => [ 'id' => 'la-052d3e2d-bc4d-4c98-8072-8d232a552299' ], 'metadata' => [ 'meta' => 'data' ] ]; $createPaymentMethod = \Xendit\DirectDebit::createPaymentMethod($params); var_dump($createPaymentMethod);
通过客户 ID 获取支付方式
\Xendit\DirectDebit::getPaymentMethodsByCustomerID(string $customer_id);
使用示例
$getPaymentMethods = \Xendit\DirectDebit::getPaymentMethodsByCustomerID('4b7b6050-0830-440a-903b-37d527dbbaa9'); var_dump($getPaymentMethods);
创建直接扣款支付
\Xendit\DirectDebit::createDirectDebitPayment(array $params);
使用示例
$params = [ 'reference_id' => 'test-direct-debit-ref', 'payment_method_id' => 'pm-ebb1c863-c7b5-4f20-b116-b3071b1d3aef', 'currency' => 'IDR', 'amount' => 15000, 'callback_url' => 'http://webhook.site/', 'enable_otp' => true, 'description' => 'test description', 'basket' => [ [ 'reference_id' => 'basket-product-ref-id', 'name' => 'product name', 'category' => 'mechanics', 'market' => 'ID', 'price' => 50000, 'quantity' => 5, 'type' => 'product type', 'sub_category' => 'product sub category', 'description' => 'product description', 'url' => 'https://product.url' ] ], 'device' => [ 'id' => 'device_id', 'ip_address' => '0.0.0.0', 'ad_id' => 'ad-id', 'imei' => '123a456b789c' ], 'success_redirect_url' => 'https://success-redirect.url', 'failure_redirect_url' => 'https://failure-redirect.url', 'metadata' => [ 'meta' => 'data' ], 'Idempotency-key' => '' . time() ]; $createDirectDebitPayment = \Xendit\DirectDebit::createDirectDebitPayment( $params ); var_dump($createDirectDebitPayment);
验证直接扣款支付的 OTP
\Xendit\DirectDebit::validateOTPForDirectDebitPayment( string $direct_debit_payment_id, array $params );
使用示例
$params = [ 'otp_code' => '222000' ]; $validateOTPForDirectDebitPayment = \Xendit\DirectDebit::validateOTPForDirectDebitPayment( 'ddpy-7e61b0a7-92f9-4762-a994-c2936306f44c', $params ); var_dump($validateOTPForDirectDebitPayment);
通过 ID 获取直接扣款支付
\Xendit\DirectDebit::getDirectDebitPaymentByID( string $direct_debit_payment_id );
使用示例
$getDirectDebitPaymentByID = \Xendit\DirectDebit::getDirectDebitPaymentByID( 'ddpy-7e61b0a7-92f9-4762-a994-c2936306f44c' ); var_dump($getDirectDebitPaymentByID);
通过参考 ID 获取直接扣款支付
\Xendit\DirectDebit::getDirectDebitPaymentByReferenceID( string $reference_id );
使用示例
$getDirectDebitPaymentByReferenceID = \Xendit\DirectDebit::getDirectDebitPaymentByReferenceID( 'test-direct-debit-ref' ); var_dump($getDirectDebitPaymentByReferenceID);
印度尼西亚的 IDR 支付
创建 IDR 支付
\Xendit\Disbursements::create(array $params);
使用示例
无idempotency key
$params = [ 'external_id' => 'disb-12345678', 'amount' => 15000, 'bank_code' => 'BCA', 'account_holder_name' => 'Joe', 'account_number' => '1234567890', 'description' => 'Disbursement from Example' ]; $createDisbursements = \Xendit\Disbursements::create($params); var_dump($createDisbursements);
有idempotency key
$params = [ 'external_id' => 'disb-12345678', 'amount' => 15000, 'bank_code' => 'BCA', 'account_holder_name' => 'Joe', 'account_number' => '1234567890', 'description' => 'Disbursement from Example', 'X-IDEMPOTENCY-KEY' => 'unique-id' ]; $createDisbursements = \Xendit\Disbursements::create($params); var_dump($createDisbursements);
创建 IDR 批量支付
\Xendit\Disbursements::createBatch(array $params);
使用示例
$batch_params = [ 'reference' => 'disb_batch-12345678', 'disbursements' => [ [ 'amount' => 20000, 'bank_code' => 'BCA', 'bank_account_name' => 'Fadlan', 'bank_account_number' => '1234567890', 'description' => 'Batch Disbursement', 'external_id' => 'disbursement-1' ], [ 'amount' => 30000, 'bank_code' => 'MANDIRI', 'bank_account_name' => 'Lutfi', 'bank_account_number' => '1234567891', 'description' => 'Batch Disbursement with email notifications', 'external_id' => 'disbursement-2', 'email_to' => ['test+to@xendit.co'], 'email_cc' => ['test+cc@xendit.co'], 'email_bcc' => ['test+bcc1@xendit.co', 'test+bcc2@xendit.co'] ] ] ]; $createBatchDisbursements = \Xendit\Disbursements::createBatch($batch_params); var_dump($createBatchDisbursements);
通过 ID 获取 IDR 支付
\Xendit\Disbursements::retrieve(string $id, array $params);
使用示例
$id = 'disbursements-id'; $retrieveParams = [ 'for-user-id' => 'test-reference-user-id' ] $getDisbursements = \Xendit\Disbursements::retrieve($id, $retrieveParams); var_dump($getDisbursements);
通过外部 ID 获取 IDR 支付
\Xendit\Disbursements::retrieveExternal(string $external_id);
使用示例
$external_id = 'disbursements-ext-id'; $getDisbursementsByExt = \Xendit\Disbursements::retrieveExternal($external_id); var_dump($getDisbursementsByExt);
获取 IDR 支付可用银行
\Xendit\Disbursements::getAvailableBanks();
使用示例
$getDisbursementsBanks = \Xendit\Disbursements::getAvailableBanks(); var_dump($getDisbursementsBanks);
菲律宾的 PHP 支付
创建 PHP 支付
\Xendit\DisbursementsPHP::createPHPDisbursement(array $params);
使用示例
无可选字段
$params = [ 'reference_id' => 'reference_id', 'currency' => 'PHP', 'amount' => 15000, 'channel_code' => 'PH_BDO', 'account_name' => 'Test', 'account_number' => '1234567890', 'description' => 'PHP Disbursement from Example', 'xendit-idempotency-key' => 'unique-id' ]; $createDisbursements = \Xendit\DisbursementsPHP::createPHPDisbursement($params); var_dump($createDisbursements);
有受益人可选字段
$params = [ 'reference_id' => 'reference_id', 'currency' => 'PHP', 'amount' => 15000, 'channel_code' => 'PH_BDO', 'account_name' => 'Test', 'account_number' => '1234567890', 'description' => 'PHP Disbursement from Example', 'xendit-idempotency-key' => 'unique-id', 'beneficiary' => [ 'type' => 'INDIVIDUAL', 'given_names' => 'Test Name', 'middle_name' => 'middle_name', 'surname' => 'surname', 'business_name' => 'business_name', 'street_line1' => 'street_line1', 'street_line2' => 'street_line2', 'city' => 'city', 'province' => 'province', 'state' => 'state', 'country' => 'country', 'zip_code' => '12345', 'mobile_number' => '9876543210', 'phone_number' => '987654321', 'email' => 'email@test.com' ] ]; $createDisbursementsWithbeneficiary = \Xendit\DisbursementsPHP::createPHPDisbursement($params); var_dump($createDisbursementsWithbeneficiary);
有收据通知可选字段
$params = [ 'reference_id' => 'reference_id', 'currency' => 'PHP', 'amount' => 15000, 'channel_code' => 'PH_BDO', 'account_name' => 'Test', 'account_number' => '1234567890', 'description' => 'PHP Disbursement from Example', 'xendit-idempotency-key' => 'unique-id', 'beneficiary' => [ 'type' => 'INDIVIDUAL', 'given_names' => 'Test Name', 'middle_name' => 'middle_name', 'surname' => 'surname', 'business_name' => 'business_name', 'street_line1' => 'street_line1', 'street_line2' => 'street_line2', 'city' => 'city', 'province' => 'province', 'state' => 'state', 'country' => 'country', 'zip_code' => '12345', 'mobile_number' => '9876543210', 'phone_number' => '987654321', 'email' => 'email@test.com' ], 'receipt_notification' => [ 'email_to' => ['test@test.com'], 'email_cc' => [], 'email_bcc' => [] ] ]; $createDisbursementsWithReceipt = \Xendit\DisbursementsPHP::createPHPDisbursement($params); var_dump($createDisbursementsWithReceipt);
通过 ID 获取 PHP 支付
\Xendit\DisbursementsPHP::getPHPDisbursementByID(string $id, array $params);
使用示例
$id = 'php-disbursements-id'; $retrieveParams = [ 'for-user-id' => 'test-reference-user-id' ] $getDisbursements = \Xendit\DisbursementsPHP::getPHPDisbursementByID($id, $retrieveParams); var_dump($getDisbursements);
通过参考 ID 获取 PHP 支付
\Xendit\DisbursementsPHP::getPHPDisbursementsByReferenceID(string $reference_id);
使用示例
$reference_id = 'reference_id'; $getDisbursementsByRef = \Xendit\DisbursementsPHP::getPHPDisbursementsByReferenceID($reference_id); var_dump($getDisbursementsByRef);
支付渠道
获取支付渠道
\Xendit\DisbursementChannels::getDisbursementChannels();
使用示例
$disbursementChannels = \Xendit\DisbursementChannels::getDisbursementChannels(); var_dump($disbursementChannels);
按渠道类别获取支付渠道
\Xendit\DisbursementChannels::getDisbursementChannelsByChannelCategory(string $channelCategory);
使用示例
$channelCategory = 'Test'; $getdisbursementChannelsByCategory = \Xendit\DisbursementChannels::getDisbursementChannelsByChannelCategory($channelCategory); var_dump($getdisbursementChannelsByCategory);
按渠道代码获取支付渠道
\Xendit\DisbursementChannels::getDisbursementChannelsByChannelCode(string $channelCode);
使用示例
$channelCode = 'Test'; $getdisbursementChannelsByCode = \Xendit\DisbursementChannels::getDisbursementChannelsByChannelCode($channelCode); var_dump($getdisbursementChannelsByCode);
电子钱包
创建电子钱包费用
\Xendit\EWallets::createEWalletCharge(array $params);
有关更多关于参数的信息,请查看Xendit API参考 - 电子钱包
使用示例
$ewalletChargeParams = [ 'reference_id' => 'test-reference-id', 'currency' => 'IDR', 'amount' => 50000, 'checkout_method' => 'ONE_TIME_PAYMENT', 'channel_code' => 'ID_SHOPEEPAY', 'channel_properties' => [ 'success_redirect_url' => 'https://yourwebsite.com/order/123', ], 'metadata' => [ 'meta' => 'data' ] ]; $createEWalletCharge = \Xendit\EWallets::createEWalletCharge($ewalletChargeParams); var_dump($createEWalletCharge);
获取电子钱包费用状态
\Xendit\EWallets::getEWalletChargeStatus(string $charge_id, array $params);
使用示例
$charge_id = 'ewc_f3925450-5c54-4777-98c1-fcf22b0d1e1c'; $eWalletStatusParam = [ 'for-user-id' => 'test-reference-user-id' ] $getEWalletChargeStatus = \Xendit\EWallets::getEWalletChargeStatus($charge_id, $eWalletStatusParam); var_dump($getEWalletChargeStatus);
取消电子钱包费用
\Xendit\EWallets::voidEwalletCharge(string $charge_id,array $params);
使用示例
$charge_id = 'ewc_f3925450-5c54-4777-98c1-fcf22b0d1e1c'; $voidEwalletChargeParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $voidEwalletCharge = \Xendit\EWallets::voidEwalletCharge($charge_id, $voidEwalletChargeParam); var_dump($voidEwalletCharge);
退款电子钱包费用
\Xendit\EWallets::refundEwalletCharge(string $charge_id,array $params);
使用示例
$charge_id = 'ewc_f3925450-5c54-4777-98c1-fcf22b0d1e1c'; $refundEwalletChargeParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $refundEwalletCharge = \Xendit\EWallets::refundEwalletCharge($charge_id, $refundEwalletChargeParam); var_dump($refundEwalletCharge);
通过 ID 获取退款
\Xendit\EWallets::getRefund(string $charge_id,string $refund_id, array $params);
使用示例
$charge_id = 'ewc_f3925450-5c54-4777-98c1-fcf22b0d1e1c'; $refund_id = 'ewr_532as23lew2321id'; $getRefundEwalletChargeParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $getRefundEwalletCharge = \Xendit\EWallets::getRefund($charge_id, $refund_id, $getRefundEwalletChargeParam); var_dump($getRefundEwalletCharge);
列出退款
\Xendit\EWallets::listRefund(string $charge_id, array $params);
使用示例
$charge_id = 'ewc_f3925450-5c54-4777-98c1-fcf22b0d1e1c'; $listRefundEwalletChargeParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $listRefundEwalletCharge = \Xendit\EWallets::listRefund($charge_id, $getRefundEwalletChargeParam); var_dump($listRefundEwalletCharge);
发票
创建发票
\Xendit\Invoice::create(array $params);
使用示例
$params = ['external_id' => 'demo_147580196270', 'payer_email' => 'sample_email@xendit.co', 'description' => 'Trip to Bali', 'amount' => 32000, 'for-user-id' => '5c2323c67d6d305ac433ba20' ]; $createInvoice = \Xendit\Invoice::create($params); var_dump($createInvoice);
获取发票
\Xendit\Invoice::retrieve(string $id, array $params);
使用示例
$id = 'invoice-id'; $retrieveParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ]; $getInvoice = \Xendit\Invoice::retrieve($id, $retrieveParam); var_dump($getInvoice);
获取所有发票
\Xendit\Invoice::retrieveAll(array $params);
使用示例
$retrieveAllParam = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ]; $getAllInvoice = \Xendit\Invoice::retrieveAll($retrieveAllParam); var_dump(($getAllInvoice));
使发票过期
\Xendit\Invoice::expireInvoice(string $id, array $params);
使用示例
$id = 'invoice-id'; $params = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ]; $expireInvoice = \Xendit\Invoice::expireInvoice($id, $params); var_dump($expireInvoice);
Paylater
启动 PayLater 计划
\Xendit\PayLater::initiatePayLaterPlans(array $params);
使用示例
$params = [ 'customer_id' => '<your-customer-id>', 'channel_code' => 'ID_KREDIVO', 'currency' => 'IDR', 'amount' => 6000000, 'order_items' => [ [ 'type' => 'PHYSICAL_PRODUCT', 'reference_id' => '1533', 'name' => 'Mobile Phone', 'net_unit_amount' => 6000000, 'quantity' => 1, 'url' => '<your-url>', 'category' => 'Smartphone' ] ] ]; $payLaterPlan = \Xendit\PayLater::initiatePayLaterPlans($params); var_dump($payLaterPlan);
创建Paylater费用
\Xendit\PayLater::createPayLaterCharge(array $params);
使用示例
$params = [ 'plan_id' => $payLaterPlan['id'], 'reference_id' => 'order_id_' . time(), 'checkout_method' => 'ONE_TIME_PAYMENT', 'success_redirect_url' => '<your-success-redirect-url>', 'failure_redirect_url' => '<your-failure-redirect-url>', ]; $payLaterCharge = \Xendit\PayLater::createPayLaterCharge($params); var_dump($payLaterCharge);
通过 ID 获取 Paylater 费用
\Xendit\PayLater::getPayLaterChargeStatus($id, array $params);
使用示例
$params = []; // Optional (You can put for-user-id if needed) $id = '<pay-later-charge-id>'; $payLaterCharge = \Xendit\PayLater::getPayLaterChargeStatus($id, $params); var_dump($payLaterCharge);
退款Paylater费用
\Xendit\PayLater::createPayLaterRefund($id, array $params);
使用示例
$params = []; // Optional (You can put for-user-id if needed) $id = '<pay-later-charge-id>'; $payLaterCharge = \Xendit\PayLater::createPayLaterRefund($id, $params); var_dump($payLaterCharge);
创建Paylater退款
\Xendit\PayLater::createPayLaterRefund($id, array $params);
使用示例
$params = []; // Optional (You can put for-user-id if needed) $id = '<pay-later-charge-id>'; $payLaterChargeRefundCreate = \Xendit\PayLater::createPayLaterRefund($id, $params); var_dump($payLaterChargeRefundCreate);
通过 ID 获取 Paylater 退款
\Xendit\PayLater::getPayLaterRefund($charge_id, $refund_id, array $params);
使用示例
$params = []; // Optional (You can put for-user-id if needed) $charge_id = '<pay-later-charge-id>'; $refund_id = '<pay-later-refund-id>'; $payLaterChargeRefund = \Xendit\PayLater::getPayLaterRefund($charge_id, $refund_id, $params); var_dump($payLaterChargeRefund);
列出 Paylater 退款
\Xendit\PayLater::listPayLaterRefund($charge_id, array $params);
使用示例
$params = []; // Optional (You can put for-user-id if needed) $charge_id = '<pay-later-charge-id>'; $payLaterChargeRefundList = \Xendit\PayLater::listPayLaterRefund($charge_id, $params); var_dump($payLaterChargeRefundList);
作废付款
\Xendit\Payouts::void(string $id);
使用示例
$id = 'payout-id'; $voidPayout = \Xendit\Payouts::void($id); var_dump($voidPayout);
支付
创建付款
\Xendit\Payouts::create(array $params);
使用示例
$params = [ 'external_id' => 'payouts-123456789', 'amount' => 50000 ]; $createPayout = \Xendit\Payouts::create($params); var_dump($createPayout);
获取付款
\Xendit\Payouts::retrieve(string $id, array $params);
使用示例
$id = 'payout-id'; $params = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $getPayout = \Xendit\Payouts::retrieve($id, $params); var_dump($getPayout);
作废付款
\Xendit\Payouts::void(string $id);
使用示例
$id = 'payout-id'; $voidPayout = \Xendit\Payouts::void($id); var_dump($voidPayout);
QR 码
创建 QR 码
\Xendit\QRCode::create(array $params);
使用示例
$params = [ 'external_id' => 'demo_123456', 'type' => 'STATIC', 'callback_url' => 'https://webhook.site', 'amount' => 10000, ]; $qr_code = \Xendit\QRCode::create($params); var_dump($qr_code)
获取 QR 码
\Xendit\QRCode::get(string $external_id);
使用示例
$qr_code = \Xendit\QRCode::get('external_123'); var_dump($qr_code);
周期性付款
创建周期性支付
\Xendit\Recurring::create(array $params);
使用示例
$params = [ 'external_id' => 'demo_147580196270', 'payer_email' => 'sample_email@xendit.co', 'description' => 'Trip to Bali', 'amount' => 32000, 'interval' => 'MONTH', 'interval_count' => 1 ]; $createRecurring = \Xendit\Recurring::create($params); var_dump($createRecurring);
获取周期性支付
\Xendit\Recurring::retrieve(string $id, array $params);
使用示例
$id = 'recurring-payment-id'; $params = [ 'for-user-id' => 'test-reference-user-id' // OPTIONAL ] $getRecurring = \Xendit\Recurring::retrieve($id, $params); var_dump($getRecurring);
编辑周期性付款
\Xendit\Recurring::update(string $id, array $params);
使用示例
$id = 'recurring-payment-id'; $params = ['amount' => 10000]; $editRecurring = \Xendit\Recurring::update($id, $params); var_dump($editRecurring);
停止周期性付款
\Xendit\Recurring::stop(string $id);
使用示例
$id = 'recurring-payment-id'; $stopRecurring = \Xendit\Recurring::stop($id); var_dump($stopRecurring);
暂停周期性付款
\Xendit\Recurring::pause(string $id);
使用示例
$id = 'recurring-payment-id'; $pauseRecurring = \Xendit\Recurring::pause($id); var_dump($pauseRecurring);
恢复周期性付款
\Xendit\Recurring::resume(string $id);
使用示例
$id = 'recurring-payment-id'; $resumeRecurring = \Xendit\Recurring::resume($id); var_dump($resumeRecurring);
零售店
创建固定支付码
\Xendit\Retail::create(array $params);
使用示例
$params = [ 'external_id' => 'TEST-123456789', 'retail_outlet_name' => 'ALFAMART', 'name' => 'JOHN DOE', 'expected_amount' => 25000 ]; $createFPC = \Xendit\Retail::create($params); var_dump($createFPC);
更新固定支付码
\Xendit\Retail::update(string $id, array $params);
使用示例
$id = 'FPC-id'; $updateParams = ['expected_amount' => 20000]; $updateFPC = \Xendit\Retail::update($id, $updateParams); var_dump($updateFPC);
获取固定支付码
\Xendit\Retail::retrieve(string $id);
使用示例
$id = 'FPC-id'; $getFPC = \Xendit\Retail::retrieve($id); var_dump($getFPC);
虚拟账户
创建固定虚拟账户
\Xendit\VirtualAccounts::create(array $params);
使用示例
$params = ["external_id" => "VA_fixed-12341234", "bank_code" => "MANDIRI", "name" => "Steve Wozniak" ]; $createVA = \Xendit\VirtualAccounts::create($params); var_dump($createVA);
获取虚拟账户银行
\Xendit\VirtualAccounts::getVABanks();
使用示例
$getVABanks = \Xendit\VirtualAccounts::getVABanks(); var_dump($getVABanks);
获取固定虚拟账户
\Xendit\VirtualAccounts::retrieve(string $id, array $params);
使用示例
$id = 'VA-id'; $params = [ 'for-user-id' => 'test-reference-user-id' //OPTIONAL ] $getVA = \Xendit\VirtualAccounts::retrieve($id, $params); var_dump($getVA);
更新固定虚拟账户
\Xendit\VirtualAccounts::update(string $id, array $params);
使用示例
$id = 'VA-id'; $updateParams = ["suggested_amount" => 1000]; $updateVA = \Xendit\VirtualAccounts::update($id, $updateParams); var_dump($updateVA);
获取固定虚拟账户支付
\Xendit\VirtualAccounts::getFVAPayment(string $paymentID);
使用示例
$paymentID = 'payment-ID'; $getFVAPayment = \Xendit\VirtualAccounts::getFVAPayment($paymentID); var_dump($getFVAPayment);
xenPlatform
创建账户
\Xendit\Platform::createAccount(array $params);
使用示例
$params = [ 'email' => 'customer@website.com', 'type' => 'OWNED', 'public_profile' => ['business_name' => 'customer company'] ]; $createAccount = \Xendit\Platform::createAccount(array $params); var_dump($createAccount);
获取账户
\Xendit\Platform::getAccount(string $account_id);
使用示例
$getAccount = \Xendit\Platform::getAccount($accountId); var_dump($getAccount);
更新账户
$updateAccount = \Xendit\Platform::updateAccount(string $account_id, array $params);
使用示例
$updateParams = [ 'email' => 'customer@website.com', 'public_profile' => ['business_name' => 'customer company updated'] ]; $updateAccount = \Xendit\Platform::updateAccount($accountId, $updateParams); var_dump($updateAccount);
创建转账
$createTransfer = \Xendit\Platform::createTransfer(array $transferParams);
使用示例
$transferParams = [ 'reference' => ''.time(), 'amount' => 50000, 'source_user_id' => '54afeb170a2b18519b1b8768', 'destination_user_id' => '5cafeb170a2b1851246b8768', ]; $createTransfer = \Xendit\Platform::createTransfer($transferParams); var_dump($createTransfer);
创建费用规则
$createFeeRule = \Xendit\Platform::createFeeRule(array $feeRuleParams);
使用示例
$feeRuleParams = [ 'name' => 'standard_platform_fee', 'description' => 'Fee charged to insurance agents based in Java', 'unit' => 'flat', 'amount' => 6500, 'currency' => 'IDR' ]; $createFeeRule = \Xendit\Platform::createFeeRule($feeRuleParams); var_dump($createFeeRule);
设置回调 URL
$setCallbackUrl = \Xendit\Platform::setCallbackUrl(string $callbackType, array $callbackUrlParams);
使用示例
$callbackUrlParams = [ 'url' => 'https://webhook.site/c9c9140b-96b8-434c-9c59-7440eeae4d7f' ]; $callbackType = 'invoice'; $setCallbackUrl = \Xendit\Platform::setCallbackUrl($callbackType, $callbackUrlParams); var_dump($setCallbackUrl);
交易
交易列表
\Xendit\Transaction::list(array $params);
使用示例
$params = [ 'types' => 'DISBURSEMENT' 'for-user-id' => 'Your User Id', //Optional 'query-param'=> 'true' //This is to enable parameters as query strings ]; $transactions = \Xendit\Transaction::list(array $params); var_dump($transactions);
交易详情
\Xendit\Transaction::detail(string $transaction_id);
使用示例
$detailTransaction = \Xendit\Transaction::detail(string $transaction_id); var_dump($detailTransaction);
报告
生成报告
\Xendit\Report::generate(array $params);
使用示例
$params = [ 'type' => 'TRANSACTIONS' ]; $generate = \Xendit\Report::generate($params); var_dump($generate);
报告详情
\Xendit\Report::detail(string $report_id);
使用示例
$detailReport = \Xendit\Report::detail('report_5c1b34a2-6ceb-4c24-aba9-c836bac82b28'); var_dump($detailReport);
异常
InvalidArgumentException
如果用户提供的参数不足以创建请求,将抛出InvalidArgumentException
。
例如,创建发票时需要一些必需的参数,如external_id
、payer_email
、description
和amount
。如果用户在尝试创建发票时缺少一个或多个参数,将抛出InvalidArgumentException
。
InvalidArgumentException
是从PHP的InvalidArgumentException
派生的。有关此异常的方法和属性的更多信息,请查看PHP文档。
ApiException
ApiException
封装了Xendit API错误。如果Xendit API端出现错误,例如使用无效的id
获取固定虚拟账户,将抛出此异常。
获取异常消息
try { $getInvoice = \Xendit\Invoice::retrieve('123'); } catch (\Xendit\Exceptions\ApiException $e) { var_dump($e->getMessage()); }
获取异常HTTP错误代码
try { $getInvoice = \Xendit\Invoice::retrieve('123'); } catch (\Xendit\Exceptions\ApiException $e) { var_dump($e->getCode()); }
获取异常Xendit API错误代码
try { $getInvoice = \Xendit\Invoice::retrieve('123'); } catch (\Xendit\Exceptions\ApiException $e) { var_dump($e->getErrorCode()); }
贡献
安装包
在开始编码之前,运行此命令以安装所有必需的包。请确保您的计算机已安装composer
。
composer install
测试
运行测试套件
vendor\bin\phpunit tests
运行示例
php examples\InvoiceExample.php
有一个预提交钩子来运行phpcs和phpcbf。请确保在提交/推送之前它们已通过。