[英]How to do a capture after an authorize? and how to do a refund? in omnipay
omnipay沒有完整的文檔! 我試圖在授權后進行捕獲,但我似乎無法做到正確。
<?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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.