paypayue / paypay-soap-php
该包已被废弃,不再维护。未建议替代包。
PHP辅助库,用于PayPay SOAP API集成。
1.12.3
2021-03-02 15:32 UTC
Requires
- php: >=5.4.0
README
PayPay PHP SOAP库
用PHP编写的PayPay SOAP API集成的官方库。
要求
- 该库需要PHP版本5.4.0或更高版本以及SOAP扩展。
安装
我们建议您使用Composer,它是PHP的包管理器。在您的项目中的composer.json文件中添加以下内容:
"require" : { "paypayue/paypay-soap-php" : "^1.0" }
在您的项目文件夹中运行以下命令
$ composer install
然后在您的代码开头添加以下行
require 'vendor/autoload.php';
如果您不能使用Composer,可以通过以下链接下载我们的PHP库,并将其集成到您的项目中。
入门
使用您的平台凭据配置环境,或使用以下内容进行测试
$config = \PayPay\Configuration::setup( array( 'environment' => 'testing', // or production 'platformCode' => '0004', 'privateKey' => 'Y1JgnTGN2lMOz8OXLs0s', 'clientId' => '503129445', // usually the client NIF 'langCode' => 'PT' ) ); $client = \PayPay\PayPayWebservice::init($config); try { $response = $client->checkIntegrationState(); } catch (\Exception $e) { // if something is not right an exception will be thrown $response = $e; }
创建支付参考
使用此方法快速获取可以发送给客户的支付参考。
$requestPayment = new \PayPay\Structure\RequestReferenceDetails( array( 'amount' => 1000, 'productCode' => 'REF123', // Optional 'productDesc' => 'Product description', // Optional 'validStartDate' => '2049-06-27T00:00:00-03:00', // Optional 'validEndDate' => '2050-06-27T23:59:59-03:00' // Optional ) );
(可选)指定支付目的银行账户
$requestPayment->withBankAccount('RDoHIUaw');
(可选)指定客户可能使用的支付选项。否则我们将使用PayPay账户上配置的选项。
$requestPayment->withPaymentOptions( [ \PayPay\Structure\RequestPaymentOption::MULTIBANCO(\PayPay\Structure\PaymentMethodType::NORMAL), // Check PaymentMethodType \PayPay\Structure\RequestPaymentOption::MBWAY(), \PayPay\Structure\RequestPaymentOption::CREDIT_CARD() ] ); try { $response = $client->createPaymentReference($requestPayment); } catch (\Exception $e) { $response = $e; } var_dump($response);
请参考以下文件以获取允许的参数
带有重定向的支付
此方法适用于即时支付的场合,例如结账过程。
try { $order = new \PayPay\Structure\RequestPaymentOrder( array( 'amount' => 1000, 'productCode' => 'REF123', // Optional 'productDesc' => 'Product description', // Optional 'validStartDate' => '2049-06-27T00:00:00-03:00', // Optional 'validEndDate' => '2050-06-27T23:59:59-03:00' // Optional ) ); $requestPayment = new \PayPay\Structure\RequestCreditCardPayment( $order, 'http://www.your_store_url.com/return', // Optional 'http://www.your_store_url.com/cancel' // Optional );
(可选)指定支付目的银行账户
$requestPayment->withBankAccount('RDoHIUaw');
(可选)指定支付选项,默认为信用卡。
$requestPayment->withMethods( array( \PayPay\Structure\PaymentMethodCode::CREDIT_CARD, \PayPay\Structure\PaymentMethodCode::MULTIBANCO, \PayPay\Structure\PaymentMethodCode::MBWAY ) ); $response = $client->doWebPayment($requestPayment); // save $response->token and $response->idTransaction // redirect to $response->url } catch (\Exception $e) { $response = $e; } var_dump($response);
附加支付信息
(可选)如果您选择发送客户信息,我们可以通过电子邮件发送支付收据
$buyer = new \PayPay\Structure\RequestBuyerInfo( array( 'firstName' => 'Manuel', 'lastName' => 'Abreu', 'email' => 'teste@teste.pt', 'customerId' => '123' ) ); $requestPayment->withBuyer($buyer);
(可选)如果您选择发送账单地址,则将其添加到支付收据中
$billingAddress = new \PayPay\Structure\RequestBillingAddress( array( 'country' => 'PT', // Country code according ISO 3166-1 'state' => '30', // State/District code according ISO 3166 Alpha-2 Code 'stateName' => 'Região Autónoma da Madeira', 'city' => 'Ribeira Brava', 'street1' => 'ACIN iCloud Solutions', 'street2' => 'Estrada Regional, 104 Nº 42-A' 'postCode' => '9350-203' ) ); $requestPayment->withBillingAddress($billingAddress);
(可选)如果您选择发送配送地址,则将其添加到支付收据中
$shippingAddress = new \PayPay\Structure\RequestShippingAddress( array( 'country' => 'PT', // Country code according ISO 3166-1 'state' => '30', // State/District code according ISO 3166 Alpha-2 Code 'stateName' => 'Região Autónoma da Madeira', 'city' => 'Ribeira Brava', 'street1' => 'ACIN iCloud Solutions', 'street2' => 'Estrada Regional, 104 Nº 42-A' 'postCode' => '9350-203' ) ); $requestPayment->withShippingAddress($shippingAddress);
发送本地生成的参考
使用以下方法发送本地生成的具有配置参考范围的参考。参考范围必须预先在PayPay中配置,只有配置范围内的参考才会被接受。
$payments = array(); $payments[] = new \PayPay\Structure\RequestPaymentReference( '12797', '812331888', 1000, "2020-06-22T08:30:49-03:00", //Optinal you can use in this format "d-m-Y H:i:s" "2020-06-22T08:30:49-03:00", "2020-07-22T08:30:49-03:00" ); try { $response = $client->saveEntityPayments($payments); } catch (\PayPay\Exception\IntegrationMultiResponseError $e) { // if something is not right an exception will be thrown $response = $e->getMultiResponseError(); //Optional you can use getIntegrationState() or getResponseErrors() to get individual response } catch (\Exception $e) { // if something is not right an exception will be thrown $response = $e; } var_dump($response);
安排重试和/或丢弃提交的参考
if (isset($response['responseErrors'])) { foreach ($response['responseErrors'] as $responseErrors) { echo 'Reference ->' . $responseErrors->reference . '<br/>'; echo 'errorCode ->' . $responseErrors->errorCode . '<br/>'; echo 'errorMessage ->' . $responseErrors->errorMessage . '<br/>'; echo '========== <br/><br/>'; } }
取消支付
使用此方法快速取消根据您的业务上下文不再有效的支付。所有支付方式都将取消,目前以下方法支持取消:
- Multibanco实时;
- 信用卡/借记卡;
- MB WAY。
try { $requestPayment = new \PayPay\Structure\RequestCancelPayment( 123456, // Payment or transaction id 'b180712cf8f6131b0d2950a83912ef7610ce0cde', // OR the payment hash 'remarks' // some remarks or comments ); $response = $client->cancelPayment($requestPayment); } catch (\Exception $e) { $response = $e; } var_dump($response);
(可选)某些方法无法取消(例如:Multibanco Normal),但您可以绕过此限制并标记支付为已取消。
$requestPayment->ignoreUnsupported();
通过Webhook处理传入的支付
使用以下方法提供处理所有成功支付的URL。
$webhook = new \PayPay\Structure\RequestWebhook( array( 'action' => \PayPay\Structure\RequestWebhook::PAYMENT_CONFIRMED, 'url' => 'htt://www.your_process_url.com' ) ); try { $response = $client->subscribeToWebhook($webhook); } catch (\Exception $e) { $response = $e; } var_dump($response);
PayPay会向您的URL发送HTTP请求,带有已确认的支付数据。您可以使用以下代码开始处理支付。
try { $webhook = \PayPay\WebhookHandler::fromPost($config); $webhook->eachPayment(function($payment) { var_dump($payment); // loop the payments }); http_response_code(200); // always return an HTTP status code. } catch (\PayPay\Exception\Webhook $e) { http_response_code($e->getCode()); echo $e->getMessage(); }
附加说明
- PayPay期望在Webhook请求的响应中收到
HTTP 200 OK
头。这表示我们已成功收到支付。否则,我们将在30分钟内间隔3次重试调用您的URL。 - 由于PayPay可能需要进行重复请求,因此作为安全措施,您应该检查每笔支付是否已经在您这边处理过。
- 请求有30秒的超时时间,因此在此过程中不建议您进行任何“重量级操作”(例如发送邮件、慢查询等)。
文档
- 官方文档(葡萄牙语)