I need to create a custom payment method in magento, so that when I create orders programaticalyl via models, I can set the "Title" of the payment to anything I want (for e.g. Cash, Invoice, etc...). A cron job will need to use this custom payment method to import orders.
So, this payment method should NOT be available at checkout, only when used via models from admin context.
So, I have the following in my custom module's system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<sections>
<payment>
<groups>
<MyCompany translate="label" module="paygate">
<label>MyCompany</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</active>
<order_status translate="label">
<label>New order status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status_processing</source_model>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</order_status>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</title>
</fields>
</MyCompany>
</groups>
</payment>
</sections>
</config>
and this is my Model/Payment.php
<?php
class MyCompany_CustomPayment_Model_Payment
extends Mage_Payment_Model_Method_Abstract
{
/**
* unique internal payment method identifier
*
* @var string [a-z0-9_]
*/
protected $_code = 'custom_payment';
/**
* Is this payment method a gateway (online auth/charge) ?
*/
protected $_isGateway = false;
/**
* Can authorize online?
*/
protected $_canAuthorize = false;
/**
* Can capture funds online?
*/
protected $_canCapture = false;
/**
* Can capture partial amounts online?
*/
protected $_canCapturePartial = false;
/**
* Can refund online?
*/
protected $_canRefund = false;
/**
* Can void transactions online?
*/
protected $_canVoid = false;
/**
* Can use this payment method in administration panel?
*/
protected $_canUseInternal = true;
/**
* Can show this payment method as an option on checkout payment page?
*/
protected $_canUseCheckout = false;
/**
* Is this payment method suitable for multi-shipping checkout?
*/
protected $_canUseForMultishipping = false;
/**
* Can save credit card information for future processing?
*/
protected $_canSaveCc = false;
/**
* Retrieve information from payment configuration
*
* @param string $field
* @param int|string|null|Mage_Core_Model_Store $storeId
*
* @return mixed
*/
/**
* Retrieve payment method title
*
* @return string
*/
public function getTitle()
{
if ($this->getInfoInstance()->getOrigData('additional_data') != '') {
return $this->getInfoInstance()->getOrigData('additional_data');
} else {
return $this->getConfigData('title');
}
}
}
When the module is installed, it appears to be working, although I can only see it in Default configuration scope (not in the store view scopes). This is what I did to enable it:
So, I tried to use it like this (only relevant code is shown, other code is snipped):
// Set Payment
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($orderInfo->StoreId)
->setCustomerPaymentId(0)
->setMethod('custom_payment')
->setAdditionalData($orderInfo->PaymentMethodTitle)
->setPo_number(' – ');
$order->setPayment($orderPayment);
When the above code executes, I get the following error/exception:
The requested Payment Method is not available.
Any idea what might be wrong? The order I am trying to create is actually for one of the store views (not the default store).