我正在尝试PayPal
在我的 Symfony2 应用程序上通过 IPN 实现支付。我正在使用 PayumBundle 和 Payum Express Check out,我已按照说明进行操作,并且系统在沙盒环境中运行良好。
这是我的控制器:
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
等,我需要执行查询以有效更新数据库上的用户信用的所有数据。我管理那个问题,我错过了一些在我的服务器和贝宝服务器之间交换的令牌的理解。发送和获取额外信息的每一个帮助将不胜感激。