Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用omnipay paypal处理paypal重定向失败者_Php_Omnipay_Paypal - Fatal编程技术网

Php 使用omnipay paypal处理paypal重定向失败者

Php 使用omnipay paypal处理paypal重定向失败者,php,omnipay,paypal,Php,Omnipay,Paypal,我已经在我的Laravel网站上实现了Omnipay paypal。 首先,我给paypal打了一个授权电话,如下所示: $invoice = $this->find($id); $gateway = Omnipay::create('PayPal_Express'); $gateway->setUsername(config('payment.paypal_api_username')); $gateway->setPassword(config('payment.paypa

我已经在我的Laravel网站上实现了Omnipay paypal。 首先,我给paypal打了一个授权电话,如下所示:

$invoice = $this->find($id);
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername(config('payment.paypal_api_username'));
$gateway->setPassword(config('payment.paypal_api_password'));
$gateway->setSignature(config('payment.paypal_signature'));
$gateway->setTestMode(config('payment.paypal_testmode'));

$response = $gateway->purchase([
    'cancelUrl' => route('paypal.cancel'),
    'returnUrl' => route('paypal.return'),
    'amount' => $invoice->price.'.00',
    'currency' => $invoice->currency->abbr,
    'Description' => 'Sandbox test transaction'
])->send();

if($response->isRedirect()) {
    // Redirect user to paypal login page
    return $response->redirect();
} else {
    Flash::error('Unable to authenticate against PayPal');        
}
在此之后,用户将被重定向到paypal的网站上进行支付,如果成功,将被重定向回returnUrl。发生这种情况时:

$payment = Payment::where('paypal_token', '=', $token)->first();
$invoice = $payment->invoice;
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername(config('payment.paypal_api_username'));
$gateway->setPassword(config('payment.paypal_api_password'));
$gateway->setSignature(config('payment.paypal_signature'));
$gateway->setTestMode(config('payment.paypal_testmode'));

$response = $gateway->completePurchase(array (
    'cancelUrl' => route('paypal.cancel'),
    'returnUrl' => route('paypal.success'),
    'amount' => $invoice->price.'.00',
    'currency' => $invoice->currency->abbr 
))->send();

if($response->isSuccessful()) {
    Event::fire(new MakePaymentEvent($invoice));
    Flash::message('Thank you for your payment!');
} else {
    Flash::error('Unable to complete transaction. Check your balance');
}
然而,从paypal返回的重定向有时会失败,可能是浏览器关闭或网络故障阻止用户返回my laravel站点

因此,我尝试创建一个cron作业(laravel中的调度程序),每5分钟检查一次未完成的付款,并尝试检查付款是否已成功转移,如果已成功转移,则将发票状态设置为payed:

$gateway = Omnipay::create('PayPal_Rest');

$gateway->initialize(array (
    'clientId' => config('payment.paypal_client_id'),
    'secret'   => config('payment.paypal_secret_id'),
    'testMode' => config('payment.paypal_testmode'),
));

$transaction = $gateway->fetchPurchase();
$transaction->setTransactionReference($token);
$response = $transaction->send();
$data = $response->getData();
dd($data);
但我只从PayPalAPI得到这个响应

array:4 [
  "name" => "INVALID_RESOURCE_ID"
  "message" => "The requested resource ID was not found"
  "information_link" => "https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID"
  "debug_id" => "8240e7d79fa91"
]
那么,当我所拥有的只是在用户被重定向之前发出的授权请求时,我应该如何获取支付交易:

#data: array:6 [▼
    "TOKEN" => "EC-9XF92859YM415352K"
    "TIMESTAMP" => "2016-02-12T14:25:09Z"
    "CORRELATIONID" => "e6a70075ad9d5"
    "ACK" => "Success"
    "VERSION" => "119.0"
    "BUILD" => "18308778"
]
我已尝试使用令牌和correlationid获取事务,但它们都不是有效的资源id

  • 我建议您从PayPal Express API切换到PayPal RESTAPI。restapi更新了,文档更完善了,而且更多 完成
  • 我建议您为每种类型提供一个唯一的返回和取消URL 交易omnipay paypal就是这样一个例子 RESTAPI的docblocks。基本上,您需要存储 调用purchase()和之前的事务数据和事务ID 使用该ID作为返回URL的一部分。然后返回URL中的代码 将知道这是用于哪个交易
  • 您创建cron作业以搜索丢失的事务的方法是正确的(我自己做这件事,但我每天只做一次),但是您需要搜索初始purchase()调用提供的事务引用,而不是返回URL中提供的事务引用
  • 因此,例如,查看您的初始代码,我添加了一些关于我将进行的更改的注释:

    // OK I'm assuming that your $id is a transaction ID, so we will use that. $invoice = $this->find($id); // Make the purchase call $response = $gateway->purchase([ // Add $id to these two URLs. 'cancelUrl' => route('paypal.cancel') . '/' . $id, 'returnUrl' => route('paypal.return') . '/' . $id, 'amount' => $invoice->price.'.00', 'currency' => $invoice->currency->abbr, 'Description' => 'Sandbox test transaction' ])->send(); if($response->isRedirect()) { // Get the transaction reference. $txnRef = $response->getTransactionReference(); // Store the above $txnRef in the transaction somewhere. // This will be the transaction reference you need to search for. // Redirect user to paypal login page return $response->redirect(); //好的,我假设您的$id是一个事务id,所以我们将使用它。 $invoice=$this->find($id); //进行购买拜访 $response=$gateway->purchase([ //向这两个URL添加$id。 'cancelUrl'=>route('paypal.cancel')./'.$id, 'returnUrl'=>route('paypal.return')./'.$id, '金额'=>美元发票->价格'.00', “货币”=>$invoice->currency->abbr, '说明'=>'沙盒测试事务' ])->send(); 如果($response->isRedirect()){ //获取事务引用。 $txnRef=$response->getTransactionReference(); //将上述$txnRef存储在事务中的某个位置。 //这将是您需要搜索的事务引用。 //将用户重定向到paypal登录页面 返回$response->redirect(); 请注意:

    • $txnRef是关键
    • 在某些交易中,您有$txnRef,但在PayPal上找不到它们。这些交易似乎已被取消,并且在一段时间后超时。如果找不到,则假定它们已被取消
    • 在PayPal fetchTransaction()调用的响应数据中,会有一些事务返回时带有不同的事务引用。这通常意味着这些事务在PayPal端已完成,您需要更新事务引用

    有关一些示例,请参阅omnipay paypal RestFetchTransactionRequest、RestFetchPurchaseRequest和RestListPurchaseRequest类中的文档。

    是的,这清楚地说明了我必须做什么。我将在几天内尝试,如果有效,我将接受您的答案。在此之前,谢谢!