|
Also Created app/code/local/Mage/WorldPay/Model/PaymentMethod.php:
<?php
class Mage_WorldPay_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
{
/**
* unique internal payment method identifier
*
* @var string [a-z0-9_]
*/
protected $_code = ‘worldpay’;
/**
* Here are examples of flags that will determine functionality availability
* of this module to be used by frontend and backend.
*
* @see all flags and their defaults in Mage_Payment_Model_Method_Abstract
*
* It is possible to have a custom dynamic logic by overloading
* public function can* for each flag respectively
*/
/**
* Is this payment method a gateway (online auth/charge) ?
*/
protected $_isGateway = true;
/**
* Can authorize online?
*/
protected $_canAuthorize = true;
/**
* Can capture funds online?
*/
protected $_canCapture = true;
/**
* Can capture partial amounts online?
*/
protected $_canCapturePartial = true;
/**
* Can refund online?
*/
protected $_canRefund = true;
/**
* Can void transactions online?
*/
protected $_canVoid = true;
/**
* 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 = true;
/**
* Is this payment method suitable for multi-shipping checkout?
*/
protected $_canUseForMultishipping = true;
/**
* Can save credit card information for future processing?
*/
protected $_canSaveCc = false;
/**
* Here you will need to implement authorize, capture and void public methods
*
* @see examples of transaction specific public methods such as
* authorize, capture and void in Mage_Paygate_Model_Authorizenet
*/
/**
* Possible result statuses
*/
const RESPONSE_CODE_APPROVED = 1;
const RESPONSE_CODE_DECLINED = 2;
const RESPONSE_CODE_ERROR = 3;
const RESPONSE_CODE_HELD = 4;
public function createFormBlock($name)
{
// create block instance
$block = $this->getLayout()->createBlock(’payment/form_cc’, $name);
// set internal method name (should be simple [a-z0-9_] string)
$block->setMethod($this->_code);
// assign payment instance to the block to get saved information for form representation
$block->setPayment($this->getPayment());
return $block;
}
public function createInfoBlock($name)
{
// create block instance
$block = $this->getLayout()->createBlock(’payment/info_cc’, $name);
// assign payment instance to the block to get saved information
$block->setPayment($this->getPayment());
return $block;
}
public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment)
{
// run CC authorization procedure
$result = $this->_authorize($payment);
// process response
switch ($result->getResponseCode()) {
case self::RESPONSE_CODE_APPROVED:
$payment->setStatus(’APPROVED’)
->setCcApproval($result->getApprovalCode())
->setCcTransId($result->getTransactionId())
->setCcAvsStatus($result->getAvsResultCode())
->setCcCidStatus($result->getCardCodeResponseCode());
$statusId = Mage::getStoreConfig(’payment/’.$this->_code.’/order_status’);
$payment->getOrder()->addStatus($statusId);
break;
case self::RESPONSE_CODE_DECLINED:
// do necessary operations on DECLINED status
$payment->setStatus(’DECLINED’)
->setStatusDescription($result->getResponseReasonText());
break;
// can add here other result options such as self::RESPONSE_CODE_ERROR
}
return $this;
}
protected function _authorize($payment)
{
$request = array(
‘x_card_num’ => $payment->getCcNumber(),
‘x_exp_date’ => sprintf(’d-d’, $payment->getCcExpMonth(), $payment->getCcExpYear())
);
$response = array(
0 => self::RESPONSE_CODE_APPROVED,
4 => ‘000000’,
6 => ‘1234567689’,
5 => ‘Y’,
);
// create result object
$result = Mage::getModel(’payment/paygate_result’);
// fill it with transaction data from $response
// example array from authorize.net
$result->setResponseCode($response[0]);
$result->setApprovalCode($response[4]);
$result->setTransactionId($response[6]);
$result->setAvsResultCode($response[5]);
return $result;
}
}
Plesae help me plaese
|