php – 如何在授权后进行捕获?以及如何退款?在omnipay
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 如何在授权后进行捕获?以及如何退款?在omnipay,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2745字,纯文字阅读大概需要4分钟。
内容图文
![php – 如何在授权后进行捕获?以及如何退款?在omnipay](/upload/InfoBanner/zyjiaocheng/749/371317422d6b4b17b7367d6a71eff4e5.jpg)
omn??ipay没有完整的文档!我试图在授权后进行捕获,但我似乎无法做到正确.
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
use Omnipay\Common\GatewayFactory;
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function authorize() {
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('***');
$gateway->setPassword('***');
$gateway->setSignature('***');
$gateway->setTestMode(true);
$response = $gateway->authorize(
array(
'cancelUrl' => base_url('welcome/authorize_return'),
'returnUrl' => base_url('welcome/authorize_return'),
'amount' => '1.99',
'currency' => 'USD'
)
)->send();
$response->redirect();
}
public function authorize_return() {
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('***');
$gateway->setPassword('***');
$gateway->setSignature('***');
$gateway->setTestMode(true);
$response = $gateway->completeAuthorize(
array(
'cancelUrl' => base_url('welcome/authorize_return'),
'returnUrl' => base_url('welcome/authorize_return'),
'amount' => '1.99',
'currency' => 'USD'
)
)->send();
echo $responsemsg = $response->getMessage();
$data = $response->getData();
$ref = $response->getTransactionReference();
$response2 = $gateway->capture($data)->send();
print_r($response2);
}
}
我需要将状态从“待定”更改为“已完成”(例如:我发货后).
我怎样才能退款?何时?如果交易状态完成,我可以退款吗?或仅在特定状态下,它们是什么?
当“付款状态”为“待定”且“已完成”时,我收到“您无法退还此类交易”:
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->gateway = GatewayFactory::create('PayPal_Express');
$this->gateway->setUsername('***');
$this->gateway->setPassword('***');
$this->gateway->setSignature('***');
$this->gateway->setTestMode(true);
}
public function refund($transactionReference, $amount) {
$ref = $transactionReference;
$data = array(
'transactionReference' => $ref,
'amount' => $amount,
);
$response = $this->gateway->refund($data)->send();
if ($response->isSuccessful()) {
// success
return 'done';
} else {
return $response->getMessage();
}
}
解决方法:
如果您想立即捕获付款,只需在初始请求中调用purchase()和completePurchase()而不是authorize()和completeAuthorize()(购买会进行组合授权和捕获).
如果您想稍后捕获付款(例如,物品发货时),则需要执行以下操作.
// after initial completeAuthorize()
// store $ref in your database with the payment
$ref = $response->getTransactionReference();
// then later, when you want to capture it
$data = array(
'transactionReference' => $ref,
'amount' => '10.00', // pass original amount, or can be less
);
$response = $gateway->capture($data)->send();
if ($response->isSuccessful()) {
// success
} else {
// error, maybe you took too long to capture the transaction
echo $response->getMessage();
}
内容总结
以上是互联网集市为您收集整理的php – 如何在授权后进行捕获?以及如何退款?在omnipay全部内容,希望文章能够帮你解决php – 如何在授权后进行捕获?以及如何退款?在omnipay所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。