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

CcAuthorizationDataBuilder.php 4.62 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\Request;

use Magento\Payment\Gateway\Request\BuilderInterface;
27
use Adyen\Payment\Observer\AdyenCcDataAssignObserver;
28 29 30 31 32 33 34 35 36 37 38 39 40

class CcAuthorizationDataBuilder implements BuilderInterface
{
    /**
     * @var \Adyen\Payment\Helper\Data
     */
    private $adyenHelper;

    /**
     * @var \Magento\Framework\App\State
     */
    private $appState;

Rik ter Beek's avatar
Rik ter Beek committed
41 42 43 44 45 46 47 48 49 50 51 52 53
    /**
     * CcAuthorizationDataBuilder constructor.
     *
     * @param \Adyen\Payment\Helper\Data $adyenHelper
     * @param \Magento\Framework\Model\Context $context
     */
    public function __construct(
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Magento\Framework\Model\Context $context
    ) {
        $this->adyenHelper = $adyenHelper;
        $this->appState = $context->getAppState();
    }
54

Rik ter Beek's avatar
Rik ter Beek committed
55 56 57 58 59 60 61 62 63 64 65 66
    /**
     * @param array $buildSubject
     * @return mixed
     */
    public function build(array $buildSubject)
    {
        /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
        $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
        $payment = $paymentDataObject->getPayment();
        $order = $paymentDataObject->getOrder();
        $storeId = $order->getStoreId();
        $request = [];
67

68
        // If ccType is set use this. For bcmc you need bcmc otherwise it will fail
Rik ter Beek's avatar
Rik ter Beek committed
69
        $request['paymentMethod']['type'] = "scheme";
attilak's avatar
attilak committed
70

71
        if ($cardNumber = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER)) {
Rik ter Beek's avatar
Rik ter Beek committed
72 73
            $request['paymentMethod']['encryptedCardNumber'] = $cardNumber;
        }
attilak's avatar
attilak committed
74

75
        if ($expiryMonth = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH)) {
Rik ter Beek's avatar
Rik ter Beek committed
76 77
            $request['paymentMethod']['encryptedExpiryMonth'] = $expiryMonth;
        }
attilak's avatar
attilak committed
78

79
        if ($expiryYear = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR)) {
Rik ter Beek's avatar
Rik ter Beek committed
80 81
            $request['paymentMethod']['encryptedExpiryYear'] = $expiryYear;
        }
attilak's avatar
attilak committed
82

Rik ter Beek's avatar
Rik ter Beek committed
83 84 85
        if ($holderName = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME)) {
            $request['paymentMethod']['holderName'] = $holderName;
        }
attilak's avatar
attilak committed
86

87
        if ($securityCode = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE)) {
Rik ter Beek's avatar
Rik ter Beek committed
88 89
            $request['paymentMethod']['encryptedSecurityCode'] = $securityCode;
        }
90

Rik ter Beek's avatar
Rik ter Beek committed
91
        // Remove from additional data
92 93 94 95
        $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER);
        $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH);
        $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR);
        $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE);
Rik ter Beek's avatar
Rik ter Beek committed
96
        $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME);
97

Rik ter Beek's avatar
Rik ter Beek committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        /**
         * if MOTO for backend is enabled use MOTO as shopper interaction type
         */
        $enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
        if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE &&
            $enableMoto
        ) {
            $request['shopperInteraction'] = "Moto";
        }
        // if installments is set add it into the request
        if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) &&
            $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) > 0
        ) {
            $request['installments']['value'] = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS);
        }
113

Rik ter Beek's avatar
Rik ter Beek committed
114 115
        return $request;
    }
116
}