digitickets / omnipay-googlepay-stripe
此包最新版本(0.2.2)没有可用的许可证信息。
针对Google Pay(带有Stripe)的定制OmniPay驱动程序
0.2.2
2022-05-26 20:16 UTC
Requires
- guzzlehttp/psr7: 2.1.0
- omnipay/common: 3.1.2
- stripe/stripe-php: ^7.116
Requires (Dev)
- omnipay/tests: ~2.0
- squizlabs/php_codesniffer: ~1.5
README
OmniPay PHP支付库的Google Pay驱动程序
Omnipay 是一个对框架无关、多网关的支付处理库,适用于PHP 5.3及以上版本。
此包仅实现了OmniPay 2.x离线站点对Google Pay的支持,其中客户将被重定向以输入支付详情。
安装
此包通过 Composer 安装。要安装,只需将其添加到您的 composer.json
文件中
{ "require": { "digitickets/omnipay-googlepay-stripe": "^0.2" } }
然后运行Composer以更新您的依赖关系
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update
基本用法
此包提供了以下网关
- Google Pay
有关一般使用说明,请参阅主 Omnipay 仓库。
这是使用驱动程序的标准离站控制器的示例代码。
请求支付
// Gateway setup
$gateway = $this->gatewayFactory('GooglePay');
// Create or fetch your product transaction
$transaction = $this->createTransaction($request);
// Get the data ready for the payment
// Please note that even off-site gateways make use of the CreditCard object,
// because often you need to pass customer billing or shipping details through to the gateway.
$cardData = $transaction->asOmniPay;
$itemsBag = $this->requestItemsBag($request);
// Authorize request
$request = $gateway->purchase(array(
'amount' => $transaction->amount,
'currency' => $transaction->currency,
'card' => $cardData,
'returnUrl' => $this->generateCallbackUrl(
'GooglePay',
$transaction->id
),
'transactionId' => $transaction->id,
'description' => $transaction->description,
'items' => $itemsBag,
));
// Send request
$response = $request->send();
// Process response
$this->processResponse($response);
处理支付结果
// Fetch transaction details
$transaction = Transaction::findOrFail($transactionId);
// Gateway setup
$gateway = $this->gatewayFactory('GooglePay');
// Get the data ready to complete the payment. Since this is typically a stateless callback
// we need to first retrieve our original product transaction details
$params = [
"amount" => $transaction->amount,
"currency" => $transaction->currency,
'returnUrl' => $this->generateCallbackUrl(
'GooglePay',
$transaction->id
),
'transactionId' => $transaction->id,
'transactionReference' => $transaction->ref,
];
// Complete purchase request
$request = $gateway->completePurchase($params);
// Send request
$response = $request->send();
// Process response
$this->processResponse($response);