0

Im creating a custom payment method on an Magento 2 website using SecurePay API. SecurePay Iframe Tokenise credit card and I will need that token to process the payment. So I follow many tutorials to add additional_data to payment but I never could get any data even with the Magento doc tutorial: devDocs

Here is my code :

securepay-method.js (in js/view/payment/method-renderer)

/**
     * Get data
     * @returns {Object}
     */
    getData: function () {
        var data = {
            'method': this.item.method,
            'additional_data': {
                'token': 'test'
            }
        };

        return data;
    },

DataAssignObserver.php (Observer)

<?php

namespace Appscore\SecurePay\Observer;


class DataAssignObserver extends AbstractDataAssignObserver
{
const TOKEN = 'token';

/**
 * @var array
 */
protected $additionalInformationList = [
    self::TOKEN,
];

/**
 * @param Observer $observer
 * @return void
 */
public function execute(Observer $observer)
{
    $data = $this->readDataArgument($observer);

    $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
    if (!is_array($additionalData)) {
        return;
    }

    $paymentInfo = $this->readPaymentModelArgument($observer);

    foreach ($this->additionalInformationList as $additionalInformationKey) {
        if (isset($additionalData[$additionalInformationKey])) {
            $paymentInfo->setAdditionalInformation(
                $additionalInformationKey,
                $additionalData[$additionalInformationKey]
            );
        }
    }
}

}

events.xml (etc)

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="payment_method_assign_data_securepay">
    <observer name="securepay_gateway_data_assign" instance="Appscore\SecurePay\Observer\DataAssignObserver" />
</event>

SecurePay (Model)

/**
 * Capture Payment.
 *
 * @param \Magento\Payment\Model\InfoInterface $payment
 * @param float $amount
 * @return $this
 */
public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
{

    $info = $this->getInfoInstance();

    var_dump($info->getAdditionalInformation());exit;
}

This always return :

array (size=1)
'method_title' => string 'Secure Pay' (length=10)

I tried everything, Im really lost on this problem, If someone can help me on this one that would be really helpfull

Thanks by advance !

0

I finally got the solution

just add in your model :

    /**
 * Set value after save payment from post data to use in case capture or authorize
 * @param \Magento\Framework\DataObject $data
 * @return $this
 */
public function assignData(\Magento\Framework\DataObject $data)
{
    parent::assignData($data);
    $this->getInfoInstance()->setAdditionalInformation('post_data_value', $data->getData());

    return $this;
}

Hope that can help someone !

0

This is still valid for 2.3.5. I just extended a NAB transact extension to display and pass a reCaptcha token to the model. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.