2

I am trying to setup payumbundle with 2checkout and I cant seem to understand how to setup config.yml and then how to send information to 2checkout.

Before this I have setup PayPal express checkout successfully with Payum and I am some what familiar with Payum (still learning about Payum)

This is what I have done so far

I have installed the omnipay 2checkout bundle

composer require "payum/omnipay-bridge" "omnipay/2checkout"

Since I cant seem to find any example online for 2checkout and the closest I found was for stripe so looking at its example This is my config.yml

payum:
    security:
        .....
    contexts:
        paypal:
            paypal_express_checkout_nvp:
                username: ....
                password: ....
                signature: ....
                sandbox: true

        2checkout:
            omnipay:
                type: TwoCheckout
                options:
                    apiKey: ....
                    pri: ....
                    act: ....
                    testMode: true

Here my first question arises

Q1: How do I know what information to add in config.yml for different gateways

Now moving on to the code inside my action that is supposed to send information to 2checkout and add data to database.

$paymentName = 'TwoCheckout';

$storage = $this->get('payum')->getStorage('ClickTeck\featuresBundle\Entity\Orders');
$paymentDetails = $storage->create();

// insert order into database
$paymentDetails->setClientFname('First');
$paymentDetails->setClientLname('Last');
$paymentDetails->setClientPhone('111-111-111');
$paymentDetails->setClientEmail('xyz@abc.com');
$paymentDetails->setInvoiceId('123');
$paymentDetails->setNumber('456');
$paymentDetails->setDescription('This is description');
$paymentDetails->setCurrencyCode('USD');
$paymentDetails->setTotalAmount('20');
$paymentDetails->setClientId($clientID);
$paymentDetails->setPaymentOption($paymentName);

$storage->update($paymentDetails);


$paymentDetails['amount'] = 20;
$paymentDetails["currency"] = 'USD';
$paymentDetails["description"] = "This is description";

$storage->update($paymentDetails);

$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
    $paymentName,
    $paymentDetails,
    'payment_done' // the route to redirect after capture;
);


return $this->redirect($captureToken->getTargetUrl());

I am using the same entity i used for PayPal and for paypal payum added data in details column of database but for 2checkout it is not adding anything for details and gives an error Integrity constraint violation thats understood because details should not be empty so here is my second question

Q2: Cant we use the same entity for different payment methods? Or each payment method should have its own entity? If we can use the same entity them why payum is not generating anything for details column. What am I doing wrong here

I will really appreciate if someone can help me in this, I need to see an example not just an explanation on how to get 2checkout integrated. However explanation will be appreciated too.

UPDATE

This is my updated code in my action that is preparing the payment which gets added to database just fine however the transaction fails

$paymentName = 'TwoCheckout';
$storage = $this->get('payum')->getStorage('ClickTeck\featuresBundle\Entity\Orders');
/** @var Orders $details */

$details = $storage->create();

// insert order into database
$details->setClientFname($form->get('client_fname')->getData());
$details->setClientLname($form->get('client_lname')->getData());
$details->setClientPhone($form->get('client_phone')->getData());
$details->setClientEmail($form->get('client_email')->getData());
$details->setInvoiceId('123');
$details->setNumber('456');
$details->setDescription('This is description');

//change currency to dynamic before live
$details->setCurrencyCode('USD');
$details->setTotalAmount($cartTotal.".00");
$details->setClientId($clientID);
$details->setPaymentOption($paymentName);



$details["sid"] = '201308888';
$details["cart_order_id"] = '123456';
$details["merchant_order_id"] = '789';
$details["total"] = $cartTotal.".00";

$details["amount"] = $cartTotal.".00";
$details["tco_currency"] = 'USD';
$details['fixed'] = 'Y';
$details['skip_landing'] = 1;
$details['card_holder_name'] = 'Hold Name';
$details['street_address'] = 'Address 1';
$details['street_address2'] = 'Address 2';
$details['city'] = 'City';
$details['state'] = 'State';
$details['zip'] = '08610';
$details['country'] = 'USA';
$details['phone'] = '111-111-111';
$details['email'] = 'dummy@xyz.com';

$details["name"] = 'a name';
$details["description"] = 'a description';
$details['card'] = new SensitiveValue(array(
    'number' => $form->get('cardNumber')->getData(),
    'cvv' => $form->get('cvv')->getData(),
    'expiryMonth' => $form->get('expiryMonth')->getData(),
    'expiryYear' => $form->get('expiryYear')->getData(),
    'firstName' => $form->get('client_fname')->getData(),
));

$storage->update($details);
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
    $paymentName,
    $details,
    'payment_done' // the route to redirect after capture;
);
$details["returnUrl"] = $captureToken->getTargetUrl();
//return $this->redirect($captureToken->getTargetUrl());
return $this->forward('PayumBundle:Capture:do', array(
    'payum_token' => $captureToken,
));

This is the response i see, I cant seem to understand why it fails

{"status":"failed","order":{"total_amount":500,"currency_code":"USD","details":{"sid":"201308888","cart_order_id":"123456","merchant_order_id":"789","total":"500.00","amount":"500.00","tco_currency":"USD","fixed":"Y","skip_landing":1,"card_holder_name":"Hold Name","street_address":"Address 1","street_address2":"Address 2","city":"city","state":"State","zip":"08610","country":"USA","phone":"111-111-111","email":"dummy@xyz.com","name":"a name","description":"a description","card":[],"returnUrl":"http:\/\/127.0.0.1:8000\/payment\/capture\/mjIo0HsxKQ1-DRISYUZ6fMZLUmOXD0-cPiOheqRqpH8","clientIp":"127.0.0.1","_reference":null,"_status":"failed","_status_code":null,"_status_message":null}}}
Shairyar
  • 3,268
  • 7
  • 46
  • 86

1 Answers1

0

Q1: How do I know what information to add in config.yml for different gateways

Payum's payment factory provide information about possible options. Its default and required values. You have to call $factory->createConfig() and looks for payum.required_options and payum.default_options (example). In the PayumBundle things even more simplier. The bundle provides factories which extend container configuration with possible options. So they will be validated by Symfony's standard config validator.

To find out which options you have to pass in Omnipay gateway you have to look at that gateway setters\getters methods (example). For example a gateway has method setTestMode, to configure it in PayumBundle you have to define an options testMode. This is how options converted to a setter call.

2Checkout I guess must be configured this way.

payum:
    contexts:
        2checkout:
            omnipay:
                type: TwoCheckout
                options:
                    accountNumber: ....
                    secretWord: ....
                    testMode: true

Q2: Cant we use the same entity for different payment methods? Or each payment method should have its own entity? If we can use the same entity them why payum is not generating anything for details column. What am I doing wrong here

From Payum perspective you may use same entity\model to store different payments. Since I've never worked with Omnipay and 2Checkout gateway I cannot help more here.

Maksim Kotlyar
  • 3,821
  • 27
  • 31
  • Many thanks for getting back to me, yesterday i did end up looking into getters and setters file to know what to add in config.yml. for future what is the easy way to know which file has getters and setters? After setting the config.yml properly with payment details the details column is now saving the data, however the card details are not being saved and i am working on that now. Since payum supports Omnipay, would you know how to pass credit card details? – Shairyar Feb 11 '15 at 09:35
  • would you have any idea when we are preparing an array to send over to the gateway what is the quick way to know what parameters are expected to be sent over for example in this case 2checkout? – Shairyar Feb 11 '15 at 13:38
  • card details are not being saved and i am working on that now. - MUST NOT BE SAVED TO DATABASE. This is correct behavior. you have to use symfony's forward instead of redirect or ask for credit card after you redirected a user to capture action. – Maksim Kotlyar Feb 11 '15 at 15:43
  • yes i am not saving them and i am using the symfony's forward. Please have a look at the updated question, i added more details under UPDATE section. – Shairyar Feb 11 '15 at 15:45