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.85 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
<?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;
27
use Adyen\Payment\Model\ApplicationInfo;
28 29

/**
30
 * Class TransactionPayment
31 32 33 34
 */
class TransactionPayment implements ClientInterface
{

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

40 41 42 43
    /**
     * @var ApplicationInfo
     */
    private $applicationInfo;
attilak's avatar
attilak committed
44

45 46 47
    /**
     * TransactionPayment constructor.
     * @param \Adyen\Payment\Helper\Data $adyenHelper
48
     * @param ApplicationInfo $applicationInfo
49 50
     */
    public function __construct(
51 52
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Adyen\Payment\Model\ApplicationInfo $applicationInfo
53 54
    ) {
        $this->adyenHelper = $adyenHelper;
55
        $this->applicationInfo = $applicationInfo;
56
    }
57

58 59
    /**
     * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
60 61
     * @return array|mixed|string
     * @throws \Adyen\AdyenException
62 63 64 65
     */
    public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
    {
        $request = $transferObject->getBody();
66
        $headers = $transferObject->getHeaders();
attilak's avatar
[WIP]  
attilak committed
67

attilak's avatar
[WIP]  
attilak committed
68
        // If the payments call is already done return the request
attilak's avatar
[WIP]  
attilak committed
69 70 71 72 73
        if (!empty($request['resultCode'])) {
            //Initiate has already a response
            return $request;
        }

74 75 76
        $client = $this->adyenHelper->initializeAdyenClient();

        $service = new \Adyen\Service\Checkout($client);
77 78 79 80 81 82

        $requestOptions = [];

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

84 85
        $request = $this->applicationInfo->addMerchantApplicationIntoRequest($request);

86
        try {
87
            $response = $service->payments($request, $requestOptions);
88 89 90 91 92 93
        } catch (\Adyen\AdyenException $e) {
            $response['error'] = $e->getMessage();
        }

        return $response;
    }
94
}