3

I'm trying to add additional data to the checkmo payment method. I then need this additional data appear at the order Endpoint.

I plan on using this as a way of passing over a sort code / account number for direct debit payments.

I have a system set up that places orders for Magento 2 with the API. A user enters name / address etc and this is sent over using the API.

For payment method I need to pass over sort code / account number. Rather than creating a custom payment method for this, I would like to try and shoehorn this information into an existing one that won't be used on the actual Magento 2 site.

The issue seems to be actually adding data into this,

The Swagger documentation seems to have -

payment": {
"account_status": "string",
"additional_data": "string",
"additional_information": [
  "string"
],

I have tried using this -

{
"paymentMethod": {
"method": "checkmo",
"additional_data": {
"sortcode" :"00-00-00",
"account_number" : "12345678"
   }
 }
}

But this still comes out at the Endpoint as -

"payment": {
    "account_status": null,
    "additional_information": [
        "Check / Money order",
        null,
        null
    ],

If I try to use additonal information instead -

{
"paymentMethod": {
"method": "checkmo",
"additional_information": {
"sortcode" :"00-00-00",
"account_number" : "12345678"
 }
}

I get the error

Message: Property "AdditionalInformation" does not have corresponding setter in class "Magento\Quote\Api\Data\PaymentInterface".

Is there anyway to add this to an order preferably using checkmo payment method, and then have it appear at the endpoint?

  • Ever found a way to set the additional info via the API? – Maikel Koek Apr 3 '18 at 17:17
1

You need to send from frontend to backend all custom information in the additional_data node. On the backend side, you need to get data from additional_data and store it in the payment additional_information. This dev guide describes how to do it.

Also, as example, you can look at Vault\PaymentTokenAssigner or Braintree\DataAssignObserver.

  • Thanks for this. I was hoping to send the order over using the API though, rather than having to touch Magento. I'll look over the links in more detail and see if I can come to some solution. – BigDaddyL Oct 20 '17 at 11:31
  • For Web API a data structure will be similar and you need to read data on the server side in the same way. – joni jones Oct 20 '17 at 11:42
0

I've ended up adding a plugin to pass the additional_information to the quote payment.

In my di.xml:

<type name="Magento\Quote\Model\Quote\Payment">
    <plugin name="vendorModuleQuotePayment" type="Vendor\Module\Plugin\QuotePaymentPlugin"/>
</type>

The plugin:

<?php

namespace Vendor\Module\Plugin;

class QuotePaymentPlugin
{
    /**
     * @param \Magento\Quote\Model\Quote\Payment $subject
     * @param array $data
     * @return array
     */
    public function beforeImportData(\Magento\Quote\Model\Quote\Payment $subject, array $data)
    {
        if (array_key_exists('additional_information', $data)) {
            $subject->setAdditionalInformation($data['additional_information']);
        }

        return [$data];
    }
}

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.