Please try the below code.
"paymentMethod": {
"method": "custom_pay",
"additional_information": {
"cc_cid": "000",
"cc_type": "VI",
"cc_exp_year": "2017",
"cc_exp_month": "2",
"cc_number": "xxxxxxxxxxxxxxxx"
}
}
I hope it will be help you.
Unfortunately, there's no way to directly access the parameters via API (we tried to do that but failed). However, we've found an alternative method to get them.
As you probably know, an API request is also classifed as 'Request', and the parameters are anyway sent to it and stored in the processApiRequest
method. If you have a closer look at it, you'll see that the \Magento\Webapi\Controller\Rest\InputParamsResolver
deals with the request parameters. Hence, we can use it to extract the needed parameters from the API request.
Add the class \Magento\Webapi\Controller\Rest\InputParamsResolver
to the di (dependency injection) of your payment class in the validate
method.
You'll get the parameters in the following way:
$inputParams = $inputParamsResolver->resolve();
The result of your request will look somewhat like this (in my example, it was implemented on the Check Money Order method):
additional_data can be found in the instance Magento\Quote\Model\Quote\Payment
.
These parameters are exactly the same, as those that are sent to a method called via API:
Just note that this approach has some pitfalls. The parameters come raw, in the array, so you'll have to sort them to find the needed ones.
P.S. If to take the quote payment directly from the quote available via payment info method,
$paymentInfo = $this->getInfoInstance();
$additionalData = $paymentInfo->getQuote()->getPayment()->getData('additional_data');
it's possible to see that the parameter from the request is not there.
Best Answer
/rest/default/V1/carts/mine/payment-information Is the rest api which map to PaymentInformationManagementInterface. Here mine means you are logged in customer.
Open vendor/magento/module-checkout/etc/webapi.xml here actually map.
When you click Place Order button, magento call vendor/magento/module-checkout/Model/PaymentInformationManagement.php
savePaymentInformationAndPlaceOrder