We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

TransactionPayment.php 2.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

namespace Adyen\Payment\Gateway\Http\Client;

use Magento\Payment\Gateway\Http\ClientInterface;

/**
 * Class TransactionSale
 */
class TransactionPayment implements ClientInterface
{

34 35 36 37
    /**
     * @var \Adyen\Payment\Helper\Data
     */
    private $adyenHelper;
38

attilak's avatar
attilak committed
39

40 41 42 43 44
    /**
     * TransactionPayment constructor.
     * @param \Adyen\Payment\Helper\Data $adyenHelper
     */
    public function __construct(
alessio's avatar
alessio committed
45
        \Adyen\Payment\Helper\Data $adyenHelper
46 47 48
    ) {
        $this->adyenHelper = $adyenHelper;
    }
49

50 51 52 53 54 55 56 57
    /**
     * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
     * @return mixed
     * @throws ClientException
     */
    public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
    {
        $request = $transferObject->getBody();
58
        $headers = $transferObject->getHeaders();
attilak's avatar
[WIP]  
attilak committed
59

attilak's avatar
[WIP]  
attilak committed
60
        // If the payments call is already done return the request
attilak's avatar
[WIP]  
attilak committed
61 62 63 64 65
        if (!empty($request['resultCode'])) {
            //Initiate has already a response
            return $request;
        }

66 67 68
        $client = $this->adyenHelper->initializeAdyenClient();

        $service = new \Adyen\Service\Checkout($client);
69 70 71 72 73 74

        $requestOptions = [];

        if (!empty($headers['idempotencyKey'])) {
            $requestOptions['idempotencyKey'] = $headers['idempotencyKey'];
        }
75 76

        try {
77
            $response = $service->payments($request, $requestOptions);
78 79 80 81 82 83
        } catch (\Adyen\AdyenException $e) {
            $response['error'] = $e->getMessage();
        }

        return $response;
    }
84
}