php - 授权后如何进行捕获?以及如何退款?在 omnipay

标签 php 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);
    }    
}

我需要将状态从“待定”更改为“已完成”(例如:在我发货后。)

enter image description here

还有我怎样才能退款,什么时候退款?如果交易状态为已完成,我可以退款吗?或仅针对特定状态,它们是什么?

当“付款状态”为“待定”和“已完成”时,我收到“您无法为此类交易退款”:

    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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18505793/

相关文章:

php - 获取 SQL 语句以选择我想要的项目的问题

php - 文件API上传文件

paypal - Omnipay/Paypal Gateway - 交易显示成功,而 Paypal 沙盒帐户不显示交易的债务/信用

php - 使用 laravel 5 的 Omnipay、paypal REST

php - Omnipay:使用 transactionId 与 transactionReference 是否有约定?

php - docker Laravel Mysql : could not find driver

php - Laravel 5.2 漂亮的 URL

php - 数据库中三个不同表之间的计算?

paypal - 如何使用 Laravel 设置 Omnipay?

php - Omnipay paypal 集成 - 确认付款状态