schmittjoh/JMSPaymentPaypalBundle — Issue #24: How to get the Payment approved?
Author: dermythos
Created: 2012-03-02 18:51:43+00:00
State: open

Hi there,

I'm trying to setup the PayPalBundle, but I really don't get It worked the right way.

At the Moment my Controller(more or less just the default one) looks like this:
(index Action creates the Payment and approve Action tries to approve it)
```
public function indexAction()
{
$paymentId = null;
$ppc = $this->container->get('payment.plugin_controller');

$instruction = new PaymentInstruction(123, 'EUR', 'paypal_express_checkout', new ExtendedData());

$ppc->createPaymentInstruction($instruction);

$paymentId = $ppc->createPayment($instruction->getId(), 123)->getId();
// Set Id to return/cancel Url
$instruction->getExtendedData()->set('return_url', 'http://www.example.com/app_dev.php/approvePayment/'.$paymentId);
$instruction->getExtendedData()->set('canel_url', 'http://www.example.com/app_dev.php/cancelPayment/'.$paymentId);
// How to set this Parameters: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_WPCustomizing
$instruction->getExtendedData()->set('checkout_params', array('L_PAYMENTREQUEST_0_NAME0' => 'Premium',
'L_PAYMENTREQUEST_0_NUMBER0' => '123',
'L_PAYMENTREQUEST_0_AMT0' => '123',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR'));

$result = $ppc->approve($paymentId, 123);

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

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

// in this case we are redirect to Paypal
if ($action instanceof VisitUrl) {
return $this->redirect($action->getUrl());
}

// no supported action
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}

// transaction was successful
return $this->render('ComEmpfehlungenBundle:Payment:approve.html.twig');

return $this->render('ComEmpfehlungenBundle:Payment:approve.html.twig');

}

public function approveAction($paymentId = null)
{
$ppc = $this->container->get('payment.plugin_controller');

$result = $ppc->approveAndDeposit($paymentId, 123);

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

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

// in this case we are redirect to Paypal
if ($action instanceof VisitUrl) {
return $this->redirect($action->getUrl());
}

// no supported action
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {

throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}

// Approve Action
return $this->render('ComEmpfehlungenBundle:Payment:approve.html.twig');
}
```
So I get redirected to PayPal. And I can pay. But I'm not shure if I works out the ammount of my Order the right way. It started to show the ammount when I added these lines:
```
$instruction->getExtendedData()->set('checkout_params', array('L_PAYMENTREQUEST_0_NAME0' => 'Premium',
'L_PAYMENTREQUEST_0_NUMBER0' => '123',
'L_PAYMENTREQUEST_0_AMT0' => '123',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR'));
```

Before I added those lines nothing was shown. So I think I have a Problem in even setting up the Payment the right way?
So If I pay at Paypal an get redirected back to my page I get the following Error-Message:
$amount must be equal to Payment's depositing amount.

So I checked the approved Ammount and it's 0.

Am I missing a critical point?
Best regards Robin