I have updated my module as below using the guidance you gave. Let me
know what you think. It seems to work fine in all cases.
<?php
class AlertPay_Order extends AlertPay_Order_parent {
// set AlertPay merchant name
protected $sMerchantId = '[email protected]';
// set AlertPay gateway URL
protected $sGatewayUrl = 'https://www.alertpay.com/PayProcess.aspx';
protected function _getNextStep($iSuccess)
{
// get current language
$lang = oxLang::getInstance()->getLanguageAbbr();
$oOrder = oxNew('oxorder');
// check that this is an AlertPay transaction
// load order information from session
if ($oOrder->load(oxSession::getVar('sess_challenge')) &&
$oOrder->oxorder__oxpaymenttype->value == 'alertpay') {
if (is_numeric($iSuccess) && $iSuccess == 1) {
// get basket and total amount
$oBasket = $this->getBasket();
$dAmount = $oBasket->getPrice()->getBruttoPrice();
// get currency
$oCur = $this->getConfig()->getActShopCurrencyObject();
$sCur = $oCur->name;
// change order status
$oOrder->oxorder__oxtransstatus = new oxField('ERROR');
$oOrder->save();
// build data for AlertPay processor
$aFormData = array(
'ap_purchasetype' => 'item-goods',
'ap_merchant' => $this->sMerchantId,
'ap_currency' => $sCur,
'ap_quantity' => '1',
'ap_returnurl' =>
'http://oxid.localhost/ap-return-'.$lang.'/?sid=' .
$this->getSession()->getId(),
'ap_itemname' => 'Shopping Cart Items and Delivery Fees',
'ap_description' =>
$this->getConfig()->getActiveShop()->oxshops__oxname->value,
// 'ap_amount' => $dAmount,
'ap_amount' => 0.01,
'ap_cancelurl' =>
'http://oxid.localhost/ap-cancel-'.$lang.'/?sid=' .
$this->getSession()->getId(),
);
// redirect to AlertPay
oxUtils::getInstance()->redirect($this->sGatewayUrl . '?' .
http_build_query($aFormData));
}
if ($iSuccess === 'AlertPayOK' &&
$oOrder->load(oxSession::getVar('sess_challenge'))) {
// if AlertPay return
// set order status to OK
// send email confirmation
$oOrder->oxorder__oxtransstatus = new oxField('OK');
$oOrder->save();
$oBasket = $this->getBasket();
$oUser = $this->getUser();
$iSuccess = $oOrder->sendAlertPayOrderByEmail($oUser, $oBasket);
} else if ($iSuccess === 'AlertPayCancel' &&
$oOrder->load(oxSession::getVar('sess_challenge'))) {
// if AlertPay cancel
// delete order from database
// return user to payment page
$oOrder->delete();
$iSuccess = 'AlertPay error';
}
}
return parent::_getNextStep($iSuccess);
}
// handles AlertPay return action
public function processAlertPayReturn()
{
$iSuccess = 'AlertPayOK';
return $this->_getNextStep($iSuccess);
}
// handles AlertPay cancel action
public function processAlertPayCancel()
{
$iSuccess = 'AlertPayCancel';
return $this->_getNextStep($iSuccess);
}
}
Arvydas wrote:
Status field value can be customized by your own, so you can set ANY
state value in this step.
--------------------------------------------------
From: "Vikram Vaswani" <[email protected]>
Sent: Monday, August 17, 2009 7:01 PM
To: <[email protected]>
Subject: Re: [oxid-dev-general][Fwd: Re:Urgent
questiononpaymentgatewayintegration]> Hi Arvydas,
Sorry, one more question :)
In the code below, you suggested overriding the order::_getNextStep
method and performing the redirection to alertpay here. However, isn't
this a little dangerous, because the order status is set to 'OK'
before order::_getNextStep method is invoked? So IMO, if the payment
transaction fails for any reason, the order status will be OK even
though the payment is not made.
Please advise, it is possible I have misunderstood the execution chain.
Vikram
Arvydas wrote:
--------------------------------------------------
1. forget oxPaymentGateway::executePayment() - in your case you
don't need it at all;
2. make a module for order with these:
<?php
// set payment method as active
protected $_blActive = true;
// set Alertpay merchant name
protected $loginId = 'XXX';
// set Alertpay gateway URL
protected $gatewayUrl = 'https://www.alertpay.com/PayProcess.aspx';
protected function _getNextStep( $iSuccess )
{
// defining that everything was fine
if ( is_numeric( $iSuccess ) && $iSuccess > 0 && $iSuccess <
2 )
$oOrder = oxNew( 'oxorder' );
if ( $oOrder->load( $this->getOrderId() ) &&
$oOrder->oxorder__oxpaymenttype->value == 'alertpay' ) {
// your code goes here
$oCur = $this->getConfig()->getActShopCurrencyObject();
$formData = array(
'ap_purchasetype' => 'item-goods',
'ap_merchant' => $this->loginId,
'ap_currency' => $oCur->name,
'ap_quantity' => '1',
'ap_returnurl' =>
'http://oxid.localhost/index.php?cl=order&fnc=processalertPay&sid='
. $this->getSession()->getId(),
'ap_itemname' => 'Shopping Cart',
'ap_description' =>
$this->getConfig()->getActiveShop()->oxshops__oxname->value,
'ap_amount' => $dAmount,
'ap_cancelurl' =>
'http://oxid.localhost/index.php?cl=payment&payerror=4&sid=' .
$this->getSession()->getId(),
'apc_1'
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general
_______________________________________________
dev-general mailing list
[email protected]
http://dir.gmane.org/gmane.comp.php.oxid.general