schmittjoh/JMSPaymentPaypalBundle — Issue #21: Basic implementation problem
Author: kpolszewski
Created: 2012-02-08 13:06:13+00:00
State: open

Hi there, I've been trying to do simple Express Checkout using provided DemoController. But I don't really know, how to get amount of money used in transaction when paypal redirects me back to my controller(i get only paymentid,token,and payerid), That's the line I'm talking about:
**$result = $ppc->approveAndDeposit($paymentId, $data['amount']);**
Any hints?
Thanks in advance.

that's my current, buggy code:

/**
* @Route("/create", name="payments_create")
* @Template()
* @Secure(roles="ROLE_USER")
*/
public function createAction() {
$request = $this->getRequest();
$form = $this->getCreateForm();

//paypal
$ppc = $this->container->get('payment.plugin_controller');
$paymentId = $request->get('paymentId');

if (null === $paymentId) {
if ($request->getMethod() == "POST") {

$form->bindRequest($request);
$data = $form->getData();
if ($form->isValid()) {
$instruction = new PaymentInstruction($data['amount'], 'EUR', 'paypal_express_checkout', new ExtendedData());
$ppc->createPaymentInstruction($instruction);

$paymentId = $ppc->createPayment($instruction->getId(), $data['amount'])->getId();

$ext_data = $instruction->getExtendedData();
$ext_data->set('return_url', $this->get('router')->generate('payments_create', array('paymentId' => $paymentId), true));
$ext_data->set('cancel_url', $this->get('router')->generate('payments_error', array(), true));
} else {
return array('new_payment_form' => $form->createView());
}
} else {
return array('new_payment_form' => $form->createView());
}
}

$result = $ppc->approveAndDeposit($paymentId, $data['amount']);

if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();

if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();

if ($action instanceof VisitUrl) {
return $this->redirect($action->getUrl());
}

throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
return $this->redirect($this->generateUrl('payments_cancel'));
}

$this->get('transactions')->topUp($data['amount'], "PayPal Transfer");
return $this->redirect($this->generateUrl('payments_success'));
}