I am using magento api
and i want to retrieve all payment methods which are enabled. When i am using cart_payment.list
API, it's giving me only one method for quote id but in my back end there are four enabled methods. How can i get all payment methods?
-
Not all payment methods are available for each quote. I would suggest the best way to debug what is going on is to recreate the quote you send via the api in the shop to see what methods can be accessed.– David MannersNov 20, 2014 at 8:37
4 Answers
magento provide List of payment according to it quote item and business logic
.AS you said all four payment is not coming that means
There are setting issue in admin
There are some business logic behind it
If you want to list of payment method then get all store payment from store config using
below code:This code only provide current store active payment.
Mage::getModel('payment/config')->getActiveMethods($storeId=null);
If want to store wise check then put store id
But want list of all payment then try this
Mage::getModel('payment/config')->getAllMethods($storeid=null).
let me know if any issue.
-
thanks for replying. but i want solution in soap v1. i am making api for android app and i am using magento api v1 for making this app. that's why i need solution in only soap v1. if you can help me then it would be great. thank u once agiain. Sep 16, 2014 at 12:55
-
are you want list payment using api v1? which will comes not depends on quote?– Amit Bera ♦Sep 16, 2014 at 12:58
-
if want to checkout using this payment then you need quote object.– Amit Bera ♦Sep 16, 2014 at 13:04
-
actually i want to set payment method using "cart_payment.method" and it only accepts what "cart_payment.list" gives. "cart_payment.method" is not allowing other payment methods. it's giving fetal error. i have quote id if u are asking about it. Sep 16, 2014 at 13:04
-
2cart_payment.list give list of payment basis of current Quote object object. You could not add any other payment methods accept cart_payment.list give list. It is magento methodology.– Amit Bera ♦Sep 16, 2014 at 13:08
When using the Magento API, not all payment methods that are enabled for your store are returned when calling cart_payment.list
.
For example, payment methods that redirect the user to an external gateway (e.g. Paypal), cannot function with an API client and are therefore excluded, for obvious reasons.
If you have built your own custom payment method and you want to make it available in your API client, you should set $_canUseInternal = true;
in your payment method model.
To understand how Magento decides if a particular payment method is available or not, take a look at app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php
:
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;
}
/**
* Checking for min/max order total for assigned payment method
*/
$total = $quote->getBaseGrandTotal();
$minTotal = $method->getConfigData('min_order_total');
$maxTotal = $method->getConfigData('max_order_total');
if ((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
return false;
}
return true;
}
So for example the free payment method (Zero Subtotal Checkout) is only available if the order total is zero.
Try this
<?php
class Excellence_Paymentfee_Model_Active_Payment
{
public function toOptionArray()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array(array('value'=>'', 'label'=>Mage::helper('adminhtml')->__('--Please Select--')));
foreach ($payments as $paymentCode=>$paymentModel) {
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = array(
'label' => $paymentTitle,
'value' => $paymentCode,
);
}
return $methods;
}
}
You can get all default Magento payment methods by this code
$allPaymentMethods = Mage::getSingleton('payment/config')->getActiveMethods();
or if you need only active methods
$allActivePaymentMethods = Mage::getSingleton('payment/config')->getActiveMethods();
But if you have some custom module with oher payment methods they not will be there. In this case you need some function to get additional payments
function getAdditionalActivePayments() {
$methods = array();
$config = Mage::getStoreConfig('custopayments_custopayments');
foreach ($config as $code => $methodConfig) {
if (Mage::getStoreConfigFlag('custopayments_custopayments/' . $code . '/active')) {
$methods[$code] = $methodConfig['title'];
// or var_dump it to see what data it has
}
}
return $methods;
}