2016-01-13 81 views
0

我有这样的代码:获取Paypal付款的回调PHP

<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1"> 
    <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
    <input type="hidden" name="business" value="<?php echo $paypal_id; ?>"> 
    <input type="hidden" name="cmd" value="_xclick"> 
    <input type="hidden" name="item_name" value="Suscripcion 1 Mes"> 
    <input type="hidden" name="userid" value="{{ Auth::User()->id }}"> 
    <input type="hidden" name="amount" value="0.1"> 
    <input type="hidden" name="currency_code" value="EUR"> 
    <input type="hidden" name="handling" value="0"> 
    <input type="hidden" name="cancel_return" value="http://betea.cf/cancel"> 
    <input type="hidden" name="return" value="http://betea.cf/success"> 
    <input type="hidden" name="invoice" value="<?php echo $random ?>"> 
    <input type="image" src="https://www.sandbox.paypal.com/es_ES/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - La manera mas segura de comprar online!"> 
    <img alt="" border="0" src="https://www.sandbox.paypal.com/es_ES/i/scr/pixel.gif" width="1" height="1"> 
    <input name="notify_url" value="http://betea.cf/success" type="hidden"> 
</form> 

而在成功的,这一点:

$id = $_POST['userid']; 
    $fecha = Carbon::now()->addMonths(1); 
    User::where('id', $id) 
     ->update(['role' => 'premium', 'expire' => $fecha]); 

但现在贝宝去的成功,说userid不存在。我如何将自定义变量传递给付款并获得成功?

+0

您使用的是IPN吗? –

+0

不,我没有使用它 – Sergio

+0

这是真的要去的方式,在网上查询关于贝宝IPN的教程,然后在您的贝宝形式,你将能够添加一个输入,将有名称“自定义”,你可以添加自定义值。然后,您会在IPN(即时付款通知)中告诉paypal查找一个php文件。在这个PHP文件中,您将能够通过paypal生成的附加字段访问对PayPal完成的整个发布请求 –

回答

1

IPN确实是交易发生后更新系统的最佳方式,但您最大的问题在于您无法将自己的字段名添加到表单中。 “userid”对PayPal系统没有任何意义,所以它会被忽略。

它们提供了一个字面上称为自定义的单个自定义字段。在该字段中,您可以包含任何您想要的值(最多256个字符),因此您可以在此处传递您的ID,然后它会返回$ _POST ['custom']。

尽管如此,使用IPN进行事后处理确实更好。