I’m trying to use Magento 2 Documentation to implement my custom credit card module payment, but i’m not able to understand the way Payment Provider Gateway works.
I folowed this doc: http://devdocs.magento.com/guides/v2.2/payments-integrations/bk-payments-integrations.html
What I understand is that it can communicate with the payment gateway I choose, but how to transfer the order info and credit card info to the payment gateway?
So, my custom payment method is showing in the checkout page. I selected it and place order but my gateway provider do not received the informations.
That’s my AuthorizationRequest.php file:
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Ahimsa\PaymentGateway\Gateway\Request; use Magento\Payment\Gateway\ConfigInterface; use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; use Magento\Payment\Gateway\Request\BuilderInterface; class AuthorizationRequest implements BuilderInterface { /** * @var ConfigInterface */ private $ config; /** * @param ConfigInterface $ config */ public function __construct( ConfigInterface $ config ) { $ this->config = $ config; } /** * Builds ENV request * * @param array $ buildSubject * @return array */ public function build(array $ buildSubject) { if (!isset($ buildSubject['payment']) || !$ buildSubject['payment'] instanceof PaymentDataObjectInterface ) { throw new \InvalidArgumentException('Payment data object should be provided'); } /** @var PaymentDataObjectInterface $ payment */ $ payment = $ buildSubject['payment']; $ order = $ payment->getOrder(); $ billing = $ order->getBillingAddress(); $ address = $ order->getShippingAddress(); return [ 'reference' => $ order->getOrderIncrementId(), 'capture' => false, 'amount' => $ order->getGrandTotalAmount(), 'cardNumber' => '4024007165823435', 'cardholderName' => 'Bill Gates', 'expirationMonth' => 02, 'expirationYear' => 2020, 'securityCode' => 317, 'uri' => 'desenvolvedores/v1/transactions' ]; } }
And the TransferFactory.php file:
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Ahimsa\PaymentGateway\Gateway\Http; use Magento\Payment\Gateway\Http\TransferBuilder; use Magento\Payment\Gateway\Http\TransferFactoryInterface; use Magento\Payment\Gateway\Http\TransferInterface; use Ahimsa\PaymentGateway\Gateway\Request\MockDataRequest; class TransferFactory implements TransferFactoryInterface { /** * @var TransferBuilder */ const URL = 'https://api.userede.com.br/'; private $ transferBuilder; /** * @param TransferBuilder $ transferBuilder */ public function __construct( TransferBuilder $ transferBuilder ) { $ this->transferBuilder = $ transferBuilder; } /** * Builds gateway transfer object * * @param array $ request * @return TransferInterface */ public function create(array $ request) { return $ this->transferBuilder ->setBody(json_encode($ request)) ->setMethod('POST') ->setHeaders([ 'Content-Type' => 'application/json', 'Authorization' => 'Basic MTAwMDAyMTA6Y2M3Yzk0MjQ1YjNhNGUxNmJlYmI2ZjE2ZTZiMTFkNjk=', 'Affiliation' => '10000210' ]) ->setUri('https://api.userede.com.br/desenvolvedores/v1/transactions') ->build(); } }
Is that the right way?
Help please!