omnipay沒有完整的文檔!我正在嘗試在授權後進行捕獲,但我似乎無法做到。如何在授權後進行捕獲?以及如何退款? in 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();
}
}
「捕獲」,你的意思是在數據庫中存儲詳細信息?你對這段代碼有什麼特別的問題? – halfer
@halfer我需要完成付款 – Waqleh