skip to Main Content

I’m integrating a payment gateway using gateway command pool.

This is di.xml

<virtualType name="AuthorizeCommand" type="MagentoPaymentGatewayCommandGatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">AuthorizationRequest</argument>
        <argument name="transferFactory" xsi:type="object">InternationalSampleGatewayHttpTransferFactory</argument>
        <argument name="client" xsi:type="object">InternationalSampleGatewayHttpClientClientMock</argument>
    </arguments>
</virtualType>

This is TransferFactory.php

public function create(array $request) {

    return $this->transferBuilder
                    ->setBody($request)
                    ->setMethod('Curl::POST')
                    ->setHeaders(['Content-Type' => 'application/json'])
                    ->setUri('https://api-gateway-sample-payments.com/transactions')
                    ->build();
}

This is ClientMock.php

public function placeRequest(TransferInterface $transferObject)
{
    //response
}

How to get CURL response in placeRequest?
How can we redirect to payment gateway page after this CURL operation?
Do we need to write separate CURL operations under placeRequest?

Please advise, I have been in a circle for days, less sleep and its catching the dateline..

Thanks

2

Answers


  1. We should perform CURL action in ClientMock – placeRequest().
    The flow of the payment gateway command pool is:

    1. Request Builder (handle order information), implement MagentoPaymentGatewayRequestBuilderInterface;
    2. ClientMock process payment action
    3. ResponseValidator (extends AbstractValidator), decides if payment is successful or not
    4. Response Handler (implements HandlerInterface), perform the final action, you may set additional information for the payment here.
    Login or Signup to reply.
  2. To use curl, use dependency injection to get an instance of the Magento Curl Client. This is easily done by

    1: importing curl with the following line at the top of your MockClient.php file:

    use MagentoFrameworkHTTPClientCurl; // use curl to make http requests
    
    1. Then you can add the param to your constructor so it is injected:
    public function __construct(
            Logger $logger,
            Curl $curl
        ) {
            $this->logger = $logger;
            // save the curl instance so you can use it
            $this->curl = $curl;
        }
    
    1. Now that you have an instance of Curl, you can make curl requests in the placeRequest function like this:
    public function placeRequest(TransferInterface $transferObject)
    {
       $this->curl->post($url, $curl_post_data);
       return $this->curl->getBody();
    }
    

    For more details on the Magento Curl Client check this link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search