Magento: Get Payment Methods (All/Active/Used)

This article shows how to get payment methods in Magento 1. We will be fetching 3 types of payment methods. They are:

1) All Payment Methods
2) Active/Enabled Payment Methods
3) Payment Methods that have been used while placing orders

To get all payment methods, we can either use Mage_Payment_Helper_Data or Mage_Payment_Model_Config class.

To get active payment methods, we will be using Mage_Payment_Model_Config class.

To get payment methods used in orders, we will be using Mage_Sales_Model_Resource_Order_Payment_Collection class.

Get all payment methods


$allPaymentMethods = Mage::helper('payment')->getPaymentMethods();
$allPaymentMethodsList = Mage::helper('payment')->getPaymentMethodList();

Sample Output:


print_r($allPaymentMethods);

Array
(
    [googlecheckout] => 
    [moneybookers_pwy] => All Polish Banks
    [amazonpayments_asp] => Amazon Simple Pay
    [banktransfer] => Bank Transfer Payment
    [braintree_basic] => Braintree
    [moneybookers_csi] => CartaSi
    [moneybookers_gcb] => Carte Bleue
    [cashondelivery] => Cash On Delivery
    [checkmo] => Check / Money order
    ...
    ...
)

Sample Output:


print_r($allPaymentMethodsList);

Array
(
    [ccsave] => Array
        (
            [active] => 0
            [cctypes] => AE,VI,MC,DI
            [model] => payment/method_ccsave
            [order_status] => pending
            [title] => Credit Card (saved)
            [allowspecific] => 0
            [group] => offline
            [useccv] => 0
            [centinel] => 0
            [min_order_total] => 
            [max_order_total] => 
            [sort_order] => 
        )

    [checkmo] => Array
        (
            [active] => 0
            [model] => payment/method_checkmo
            [order_status] => pending
            [title] => Check / Money order
            [allowspecific] => 0
            [group] => offline
            [payable_to] => 
            [mailing_address] => 
            [min_order_total] => 
            [max_order_total] => 
            [sort_order] => 
        )

    [free] => Array
        (
            [active] => 1
            [model] => payment/method_free
            [order_status] => pending
            [title] => No Payment Information Required
            [allowspecific] => 0
            [sort_order] => 1
            [group] => offline
        )

    [purchaseorder] => Array
        (
            [active] => 0
            [model] => payment/method_purchaseorder
            [order_status] => pending
            [title] => Purchase Order
            [allowspecific] => 0
            [group] => offline
            [min_order_total] => 
            [max_order_total] => 
            [sort_order] => 
        )
    ...
    ...
)

Get all and active payment methods


$allPaymentMethods = Mage::getModel('payment/config')->getAllMethods();
$activePaymentMethods = Mage::getModel('payment/config')->getActiveMethods();

Both of the above variables have similar format of output.

Sample Output:


print_r($activePaymentMethods);

Array
(
    [free] => Mage_Payment_Model_Method_Free Object
        (
            [_canAuthorize:protected] => 1
            [_code:protected] => free
            [_formBlockType:protected] => payment/form
            [_infoBlockType:protected] => payment/info
            [_isGateway:protected] => 
            [_canOrder:protected] => 
            [_canCapture:protected] => 
            [_canCapturePartial:protected] => 
            [_canCaptureOnce:protected] => 
            [_canRefund:protected] => 
            [_canRefundInvoicePartial:protected] => 
            [_canVoid:protected] => 
            [_canUseInternal:protected] => 1
            [_canUseCheckout:protected] => 1
            [_canUseForMultishipping:protected] => 1
            [_isInitializeNeeded:protected] => 
            [_canFetchTransactionInfo:protected] => 
            [_canReviewPayment:protected] => 
            [_canCreateBillingAgreement:protected] => 
            [_canManageRecurringProfiles:protected] => 1
            [_canCancelInvoice:protected] => 
            [_debugReplacePrivateDataKeys:protected] => Array
                (
                )

            [_data:protected] => Array
                (
                    [id] => free
                    [store] => 
                )

            [_hasDataChanges:protected] => 1
            [_origData:protected] => 
            [_idFieldName:protected] => 
            [_isDeleted:protected] => 
            [_oldFieldsMap:protected] => Array
                (
                )

            [_syncFieldsMap:protected] => Array
                (
                )

        )

    [cashondelivery] => Mage_Payment_Model_Method_Cashondelivery Object
        (
            [_code:protected] => cashondelivery
            [_formBlockType:protected] => payment/form_cashondelivery
            [_infoBlockType:protected] => payment/info
            [_isGateway:protected] => 
            [_canOrder:protected] => 
            [_canAuthorize:protected] => 
            [_canCapture:protected] => 
            [_canCapturePartial:protected] => 
            [_canCaptureOnce:protected] => 
            [_canRefund:protected] => 
            [_canRefundInvoicePartial:protected] => 
            [_canVoid:protected] => 
            [_canUseInternal:protected] => 1
            [_canUseCheckout:protected] => 1
            [_canUseForMultishipping:protected] => 1
            [_isInitializeNeeded:protected] => 
            [_canFetchTransactionInfo:protected] => 
            [_canReviewPayment:protected] => 
            [_canCreateBillingAgreement:protected] => 
            [_canManageRecurringProfiles:protected] => 1
            [_canCancelInvoice:protected] => 
            [_debugReplacePrivateDataKeys:protected] => Array
                (
                )

            [_data:protected] => Array
                (
                    [id] => cashondelivery
                    [store] => 
                )

            [_hasDataChanges:protected] => 1
            [_origData:protected] => 
            [_idFieldName:protected] => 
            [_isDeleted:protected] => 
            [_oldFieldsMap:protected] => Array
                (
                )

            [_syncFieldsMap:protected] => Array
                (
                )

        )

    [paypal_standard] => Mage_Paypal_Model_Standard Object
        (
            [_code:protected] => paypal_standard
            [_formBlockType:protected] => paypal/standard_form
            [_infoBlockType:protected] => paypal/payment_info
            [_isInitializeNeeded:protected] => 1
            [_canUseInternal:protected] => 
            [_canUseForMultishipping:protected] => 
            [_config:protected] => 
            [_isGateway:protected] => 
            [_canOrder:protected] => 
            [_canAuthorize:protected] => 
            [_canCapture:protected] => 
            [_canCapturePartial:protected] => 
            [_canCaptureOnce:protected] => 
            [_canRefund:protected] => 
            [_canRefundInvoicePartial:protected] => 
            [_canVoid:protected] => 
            [_canUseCheckout:protected] => 1
            [_canFetchTransactionInfo:protected] => 
            [_canReviewPayment:protected] => 
            [_canCreateBillingAgreement:protected] => 
            [_canManageRecurringProfiles:protected] => 1
            [_canCancelInvoice:protected] => 
            [_debugReplacePrivateDataKeys:protected] => Array
                (
                )

            [_data:protected] => Array
                (
                    [id] => paypal_standard
                    [store] => 
                )

            [_hasDataChanges:protected] => 1
            [_origData:protected] => 
            [_idFieldName:protected] => 
            [_isDeleted:protected] => 
            [_oldFieldsMap:protected] => Array
                (
                )

            [_syncFieldsMap:protected] => Array
                (
                )

        )

)

Get used payment methods

To get all the payment methods that have been used while placing orders, we use the following code:


$collection = Mage::getResourceModel('sales/order_payment_collection');
$collection->getSelect()->group('method');
$usedPaymentMethods = array();
foreach ($collection as $col) { 
    $usedPaymentMethods[] = $col->getMethod();
}

Sample Output:


print_r($usedPaymentMethods);

Array
(
    [0] => cashondelivery
    [1] => ccsave
    [2] => checkmo
    [3] => paypal_standard
)

Hope this helps. Thanks.