成功后未收到PayPal的响应



我已经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');

谁能帮我解决这个问题?

在处理PayPal时,您必须实现IPN(即时付款通知)以获取付款状态,无论它是成功还是失败。

为此,您必须在PayPal帐户中的设置下激活IPN,并提供系统的URL以接收IPN数据,并且该URL必须是post类型。

如果我没记错的话,您已经为相同的网址创建了此URL:

Route::get('payment-success' , 'PaymentController@payment_success');

但问题是,它是get类型,因此请将其更改为"发布"并重试。如果此 url 不用于相同的目的,则为相同的目的创建一个 URL。

PS:出于测试目的,PayPal提供了一个IPN模拟器来测试相同的过程,使用该模拟器将非常有帮助。

IPN 模拟器参考

相关内容

  • 没有找到相关文章

最新更新