我正在尝试通过我的Symfony2应用程序上的IPN实施PayPal
付款。
我正在使用PayumBundle和Payum Express Check,我遵循了这些说明,系统在沙盒环境中运行良好。
以下是我的控制器:
public function preparePaypalExpressCheckoutPaymentAction($almount)
{
$paymentName = 'paypall';
$storage = $this->get('payum')->getStorageForClass(
'Acme\MyBundle\Entity\PaymentDetails',
$paymentName
);
$paymentDetails = $storage->createModel();
$paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
$paymentDetails['PAYMENTREQUEST_0_AMT'] = $almount;
//Aggiunti
$paymentDetails['PAYMENTREQUEST_0_AMT'] = $almount;
$paymentDetails['PAYMENTREQUEST_0_ITEMAMT'] = $almount;
$paymentDetails['PAYMENTREQUEST_0_PAYMENTACTION'] = "sale";
$paymentDetails['L_PAYMENTREQUEST_0_NAME0'] = "Recharge";
$paymentDetails['L_PAYMENTREQUEST_0_QTY0'] = 1;
$paymentDetails['L_PAYMENTREQUEST_0_AMT0'] = $almount;
$paymentDetails['NOSHIPPING'] = Api::NOSHIPPING_NOT_DISPLAY_ADDRESS;
$storage->updateModel($paymentDetails);
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
$paymentName,
$paymentDetails,
'Genia_sepeda_quickpayResponse' // the route to redirect after capture;
);
$paymentDetails['INVNUM'] = $paymentDetails->getId();
$paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
$paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
$storage->updateModel($paymentDetails);
return $this->redirect($captureToken->getTargetUrl());
///////////////////////////////////////////
}
public function captureDoneAction(Request $request)
{
$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
$status = new BinaryMaskStatusRequest($token);
$payment->execute($status);
if ($status->isSuccess()) {
// UPDATE USER DATA HERE
$this->get('session')->getFlashBag()->set(
'notice',
'Successo!. Ricarica effettuata.'
);
$em = $this->get('doctrine')->getEntityManager();
$user= $em->getRepository('AcmeMyBundle:User')->find(1); // JUST FOR TRY
$credit=$user->getCredit();
$em->persist($user)
$em->flush();
} else if ($status->isPending()) {
$this->get('session')->getFlashBag()->set(
'notice',
'Pagamento In Sospeso. Il credito verrà aggiornato non appena il pagamento avrà successo.'
);
} else {
$this->get('session')->getFlashBag()->set('error', 'Pagamento Fallito.');
}
foreach ($this->get('session')->getFlashBag()->get('notice', array()) as $message) {
echo "<div class='flash-notice'>$message</div>";
}
foreach ($this->get('session')->getFlashBag()->get('error', array()) as $message) {
echo "<div class='flash-notice'>$message</div>";
}
return new response("END");
//return $this->redirect('homepage');
}
使用基本配置,我可以设置支付的挂载,并发送到PayPal页面,用户可以登录并传递付款,从控制器正确拦截回调并处理captureDoneAction ()。
现在我的问题是添加其他信息以发送给PayPal
它应该返回给我,如User_id
,almount
等,我需要将所有数据扩展到有效的查询更新我的数据库上的用户信用。
我管理那个problamy我想念我的服务器和paypal服务器之间的令牌。每个帮助发送和获取额外的iformation将很多将被赞赏。
答案 0 :(得分:0)
如果我找到了你,你需要一个$ paymentDetails模型。如果是这样,请阅读Payum - PaymentDetails object in done action where is
上的答案您可以扩展此模型'Acme \ MyBundle \ Entity \ PaymentDetails'并添加与您的用户以及其他一些不需要PayPal但可以由您使用的字段的关系。
顺便说一句,你从控制器那里echo
。它不是Symfony方式,Concat将所有html变为变量并将其与Response对象一起返回。