【问题标题】:How to do a capture after an authorize? and how to do a refund? in omnipay授权后如何抓拍?以及如何退款?在omnipay
【发布时间】:2013-09-01 13:59:12
【问题描述】:

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 我需要完成付款

标签: php omnipay


【解决方案1】:

如果您想立即获取付款,只需在您的初始请求中调用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();
}

【讨论】:

  • 好的,谢谢,我确实想捕获(发货后),但我也想知道如何退款我可以在你的答案中使用 asme $data 数组吗?
  • 是的,要退款,您使用相同的数组,除了您不需要传递金额,只需传递 transactionReference。您只能在捕获交易后退款。确保传递从 capture() 调用中获得的新 transactionReference,而不是来自初始 authorize() 的 transactionReference。
猜你喜欢
  • 2016-05-24
  • 2020-01-06
  • 2020-12-25
  • 2015-12-19
  • 2018-04-08
  • 2014-04-07
  • 2016-08-15
  • 2017-01-27
  • 1970-01-01
相关资源
最近更新 更多