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}}}