我已将Paypal与我的Laravel应用程序集成。我可以从Paypal成功付款,但是成功付款后,我无法在我的网站上收到任何类型的回复。
我的代码如下:
public function aCoolFunction(CreateDistrictRequest $request)
{
$data = $request->only('city_id', 'name', 'latitude', 'longitude');
$district = $this->districtRepository->create($data);
$payment = 'sandbox';
$values = [
'charest' => 'utf-8',
'lc' => 'US',
'cmd' => '_xclick',
'amount' => $product->price, // PRICE
'business' => 'test-facilitator@gmail.com', // PAYPAL EMAIL
'item_name' => $product->name, // NAME
'item_number' => $product->id, // ITEM ID
'currency_code' => 'USD',
'no_note' => '0',
'tax_rate' => 0, // 0- TO NOT ADD ANY FEES
'no_shipping' => 1, // NO ADDRESS
'rm' => '1',
'page_style' => 'paypal',
'custom' => '1', // ANY VALUES TO RETURN IT AFTER PAYMENT SUCCESS
'return' => url('payment-status'), // RETURN - MUST BE A VALID URL
'cancel_return' => url('payment-cancel'),
'notify_url' => url('payment-ipn') // IPN PAYPAL - CHECK IF IS PAID
];
$pay_url = "https://www.paypal.com/cgi-bin/webscr";
// CREATE $payment TO CHECK IF IS SANDBOX or LIVE - FROM CONFIG FILE FOR EXAMPLE
if ($payment == 'sandbox') :
$pay_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
endif;
return view('paypalpayment', ['pay_url' => $pay_url, 'values' => $values]);
}
public function paymentInfo(Request $request)
{
$myfile = fopen("paypalog.txt", "w") or die('Cannot open file: ' . $my_file);
$data = 'Transaction id = ' . $request;
fwrite($myfile, $data);
if ($request->tx)
{
if ($payment = Payment::where('transaction_id', $request->tx)->first())
{
$payment_id = $payment->id;
}
else
{
$payment = new Payment;
$payment->item_number = $request->item_number;
$payment->transaction_id = $request->tx;
$payment->currency_code = $request->cc;
$payment->payment_status = $request->st;
$payment->save();
$payment_id = $payment->id;
}
return 'Pyament has been done and your payment id is : ' . $payment_id;
}
else
{
return 'Payment has failed';
}
}
public function payment_success(Request $req)
{
$myfile = fopen("paypalog1.txt", "w") or die('Cannot open file: ' . $my_file);
$data = 'Transaction id = ' . $request->tx;
fwrite($myfile, $data);
}
上面的代码paymentinfo()
中的是成功或失败从Paypal付款的呼叫。但是在这里,我无法从Paypal收到任何有关付款的回复。
这是我的路线
Route::get('payment-status',array('as'=>'payment.status','uses'=>'PaymentController@paymentInfo'));
Route::get('payment',array('as'=>'payment','uses'=>'PaymentController@payment'));
Route::get('payment-cancel', function () {
return 'Payment has been canceled';
});
Route::get('payment-success' , 'PaymentController@payment_success');
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
在处理PayPal时,您必须实施IPN
(即时付款通知)以获取付款状态(无论成功还是失败)。
为此,您必须在PayPal帐户中的设置下激活IPN,并提供系统的URL以接收IPN数据,并且该URL必须为post
类型。
如果我没记错的话,您已经使用相同的网址创建了该网址:
Route::get('payment-success' , 'PaymentController@payment_success');
但是问题是,它属于get
类型,因此请将其更改为“ post”,然后重试。如果此网址不是出于相同的目的,请为该网址创建一个网址。
PS :出于测试目的,PayPal提供了一个IPN模拟器来测试同一过程,使用它会非常有帮助。
IPN模拟器reference