I'm trying to use JMSPaymentCoreBundle
with JMSPaymentPaypalBundle
and I can't find a clear example anywhere on how to do it.
I've done all steps specified in the documentation and I'm not able to get it working. Can anybody help me please?
Payum bundle supports jms payments via the bridge. The links describes how to get started.
Usage of the bundle gives you several advantages:
P.S. It is not the full list of features.
The default way to create a payment instruction is through the jms_choose_payment_method form:
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => 12.99,
'currency' => 'EUR',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true),
'cancel_url' => $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true)
),
),
));
You can also create a payment instruction manually:
use JMS\Payment\CoreBundle\Entity\ExtendedData;
use JMS\Payment\CoreBundle\Entity\Payment;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;
$extendedData = new ExtendedData();
$extendedData->set('return_url', $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true));
$extendedData->set('cancel_url', $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true));
$instruction = new PaymentInstruction((float)$order->getCharge() > 0 ? $order->getCharge() : $order->getAmount(), 'EUR', 'paypal_express_checkout', $extendedData);
$this->get('payment.plugin_controller')->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($order);
$em->flush();
My payment_complete route looks like:
public function completeAction(Booking $order)
{
$instruction = $order->getPaymentInstruction();
if (($instruction->getAmount() - $instruction->getDepositedAmount()) > 0) {
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->get('payment.plugin_controller')->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}
$result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();
if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();
if ($action instanceof VisitUrl) {
return new RedirectResponse($action->getUrl());
}
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}
}
$order->setTransactionAmount((float)$order->getAmount());
$creditPurchased = (float)$order->getCharge() > (float)$order->getAmount() ? (float)$order->getCharge() - (float)$order->getAmount() : 0;
$em->persist($order);
$em->flush();
I've got it running going through http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With