Php 难以使用payum捆绑包管理数据
我正在尝试在我的Symfony2应用程序上通过IPN实现PayPal支付。 我使用PayumBundle和Payum Express签出,我遵循了指令,系统在沙盒环境中运行良好 这是我的控制器:Php 难以使用payum捆绑包管理数据,php,symfony,paypal,doctrine-orm,payum,Php,Symfony,Paypal,Doctrine Orm,Payum,我正在尝试在我的Symfony2应用程序上通过IPN实现PayPal支付。 我使用PayumBundle和Payum Express签出,我遵循了指令,系统在沙盒环境中运行良好 这是我的控制器: public function preparePaypalExpressCheckoutPaymentAction($almount) { $paymentName = 'paypall'; $storage = $this->get('payum')->getStorag
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页面,用户可以登录并传递付款,从控制器正确截获回调并处理CapturedOnAction。
现在,我的问题是添加额外的信息发送到PayPal,它应该返回给我,如用户id、almount等,所有我需要的数据来执行查询,以有效地更新我数据库中的用户信用。
我发现我在理解我的服务器和paypal服务器之间交换的令牌时遗漏了一些东西。发送和获取额外信息的每一个帮助都将不胜感激。如果我没弄错,您需要一个$paymentDetails模型。如果是这样,请阅读上的答案 您可以扩展此模型“Acme\MyBundle\Entity\PaymentDetails”,并添加与您的用户的关系以及一些不需要paypal但您可以使用的其他字段 顺便说一句,你从控制器那里得到了回音。它不是Symfony方式,将所有html连接到变量,并将其与响应对象一起返回