Setting up a payment method to cart using Magento API
I am using Magento API to create orders. My code doesn't work when I want to add a payment method to my cart:
$paymentMethod = array(
"method" => "paypal_standard"
);
$resultPaymentMethod = $proxy->call(
$sessionId,
"cart_payment.method",
array(
$shoppingCartId,
$paymentMethod
)
);
I get the following error: Payment method not allowed.
In the admin section under System-> Configuration-> PayPal I have set the website payment standard, but I have not enabled any option in System-> Configuration-> Payment Methods because there are no PayPal available. When I call:
$proxy->call($session, 'cart_payment.list')
method I am getting an empty array as there are no payment methods available. Does anyone know how and where PayPal payment is saved in Magento?
If I set a different payment method like "checkmo" then the order will be created perfectly. The thing is, I only need to allow standard Paypal payment.
So my question is, how can I set the PayPal payment method to my cart so that my order is successfully created?
Thank.
source to share
I also have this problem and find the cause.
$ method-> canUseInternal () used in payment method api. When we use paypal or other redirecting methods in the methos api payment method, in this case $ method-> canUseInternal () gets false.
So, for such a situation, we need to create our own custom encoding.
Api refreance function:
protected function _canUsePaymentMethod($method, $quote){
if (!($method->isGateway() || $method->canUseInternal())) {
return false; }
if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) {
return false;
}
if (!$method->canUseForCurrency(Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode())) {
return false;
}
source to share