Php 使用omnipay paypal处理paypal重定向失败者
我已经在我的Laravel网站上实现了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
$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
- $txnRef是关键
- 在某些交易中,您有$txnRef,但在PayPal上找不到它们。这些交易似乎已被取消,并且在一段时间后超时。如果找不到,则假定它们已被取消
- 在PayPal fetchTransaction()调用的响应数据中,会有一些事务返回时带有不同的事务引用。这通常意味着这些事务在PayPal端已完成,您需要更新事务引用
有关一些示例,请参阅omnipay paypal RestFetchTransactionRequest、RestFetchPurchaseRequest和RestListPurchaseRequest类中的文档。是的,这清楚地说明了我必须做什么。我将在几天内尝试,如果有效,我将接受您的答案。在此之前,谢谢!