Search code examples
phpsymfonypaypalpayum

Not able to send payment to PayPal using Symfony


I am using Symfony and trying to send payment details to PayPal using PayumBundle, I got PayumBundle configured and I got it to work until getting redirected to paypal but no payment details were being sent so I searched on line and came across this question in SO and this is the exact blank information screen I am seeing.

Looking at the documentation that answer is pointing to I came up with the following piece of code but when I try to access to route that is calling the following prepare Action. I run into an error

public function prepareAction(Request $request)
{
    $paymentName = 'paypal';

    $storage = $this->getPayum()->getStorage('ClickTeck\featuresBundle\Entity\Orders');

    /** @var \ClickTeck\featuresBundle\Entity\Orders $paymentDetails */
    $paymentDetails = $storage->create();
    $paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
    $paymentDetails['PAYMENTREQUEST_0_AMT'] = 1500;
    $storage->update($paymentDetails);

    $notifyToken = $this->getTokenFactory()->createNotifyToken($paymentName, $paymentDetails);
    $captureToken = $this->getTokenFactory()->createCaptureToken(
        $paymentName,
        $paymentDetails,
        'payment_done'
    );

    $paymentDetails['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyToken->getTargetUrl();
    $paymentDetails['INVNUM'] = $paymentDetails->getId();
    $storage->update($paymentDetails);
    return $this->redirect($captureToken->getTargetUrl());

}

Error: Cannot use object of type ClickTeck\featuresBundle\Entity\Orders as array

I then tried using the following but that leads to another error at paypal end

$paymentDetails->PAYMENTREQUEST_0_CURRENCYCODE = 'USD';
$paymentDetails->PAYMENTREQUEST_0_AMT = 1500;

This transaction cannot be processed. The amount to be charged is zero

This is how my Order Entity looks like

<?php

namespace ClickTeck\featuresBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\Order as BaseOrder;


/**
 * Orders
 */
class Orders extends BaseOrder
{
    /**
     * @var integer
     */
    protected $id;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
}

Can someone please help me find out what is this happening? Its been 2 days I am trying to make the PayumBundle work.

I will really appreciate any help in this. How do I send payment details to PayPal?


Solution

  • A bit of theory:

    You messed to different ways of using Payum. First one is completely custom (other words payment specific format). In this case you can use whatever that implements \ArrayAccess interface. The fields names and their values looks same as they are in Paypal docs.

    The other way is a thin layer over first one which adds unification. Here you have to use Order model and fill it using available setters. You can still add some specific fields using setDetails method.

    There is a third method: Use your own model (Order\Invoice\Payment you name it) and provide an integration inside Payum.

    Now the answer:

    How does this \ClickTeck\featuresBundle\Entity\Orders model look like? Do you implement OrderInterface or extend ArrayObject from Payum? I guess the first one. If you want to use completely custom solution extend ArrayObject and use it as array. If you need unified variant (you are going to other payment in future) go with Order