I'm tryng to implement PayPal
payment via IPN on my Symfony2 application.
I'm using the PayumBundle and Payum Express Check out, I've followed the istructions, and the system works fine in the sand-box environment.
Here are my Controllers:
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');
}
With the base configuration I'm able to set the almount of the payment, and send to the PayPal page, the user is able to put his login and pass a pay, the callback is correctly intercepted from the controller and processed captureDoneAction().
Now my problem is to add additional information to send to PayPal
that it should return to me, like the User_id
, the almount
, etc, all data I need to extecute the queries to effectly update the user credit on my database.
I admin that problamy I miss something in the understand of the token excanged between my server and paypal server. Every help to send and grab additional iformation will be alot will be appreciated.