Paypal PHP Integration Omnipay中的“无效请求-查看详细信息”

问题描述

我已经将此Paypal Payment与Omnipay集成到了我的PHP应用程序中

在我的index.PHP中,

<form action="process.PHP" method="POST">
    <button type="submit">Pay with Paypal</button>
</form>

在我的process.PHP中,我已经完成了

<?PHP

require_once 'config.PHP';
 
try {
    $response = $gateway->purchase(array(
        'amount' => 100,'currency' => PAYPAL_CURRENCY,'returnUrl' => PAYPAL_RETURN_URL,'cancelUrl' => PAYPAL_CANCEL_URL,))->send();

    if ($response->isRedirect()) {
        $response->redirect(); // this will automatically forward the customer
    } else {
        // not successful
        dd($response->getMessage());
    }
} catch(Exception $e) {
    dd($e);
}

function dd($content)
{
    echo  "<pre>";
        var_dump($content);
    echo "</pre>";
} 

在我的config.PHP中,我已经完成了

<?PHP

    require_once "vendor/autoload.PHP";
     
    use Omnipay\Omnipay;
     
    define('CLIENT_ID','my-client-id');
    define('CLIENT_SECRET','my-secret-id');
     
    define('PAYPAL_RETURN_URL','localhost/paypalwp/success.PHP');
    define('PAYPAL_CANCEL_URL','localhost/paypalwp/cancel.PHP');
    define('PAYPAL_CURRENCY','USD'); // set your currency here
     
     
    $gateway = Omnipay::create('PayPal_Rest');
    $gateway->setClientId(CLIENT_ID);
    $gateway->setSecret(CLIENT_SECRET);
    $gateway->setTestMode(true); //set it to 'false' when go live 

在我的success.PHP中,我已经完成了

<?PHP

    require_once 'config.PHP';
     
    // Once the transaction has been approved,we need to complete it.
    if (array_key_exists('paymentId',$_GET) && array_key_exists('PayerID',$_GET)) {
        $transaction = $gateway->completePurchase(array(
            'payer_id'             => $_GET['PayerID'],'transactionReference' => $_GET['paymentId'],));
        $response = $transaction->send();
     
        if ($response->isSuccessful()) {
            // The customer has successfully paid.
            $arr_body = $response->getData();
     
            $payment_id = $arr_body['id'];
            $payer_id = $arr_body['payer']['payer_info']['payer_id'];
            $payer_email = $arr_body['payer']['payer_info']['email'];
            $amount = $arr_body['transactions'][0]['amount']['total'];
            $currency = PAYPAL_CURRENCY;
            $payment_status = $arr_body['state'];
     
            echo "Payment is successful. Your transaction id is: ". $payment_id;
        } else {
            echo $response->getMessage();
        }
    } else {
        echo 'Transaction is declined';
    }

并且在cancel.PHP中,我有一个简单的html布局,表示用户已取消付款

但是当我尝试这段代码时,它给了我这个错误"Invalid request - see details"

知道为什么要这么做吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...