Breaking News
Loading...

Creating Payment Gateway

05:43

Create Your Payment Gateway App For E-Commerce



Build Structure For Your Payment Gateway For Buying Product And Your E-Commerce Application.


Its Provide The Path Of Payment Of Buyer To Owner.

Payment Gateway is Need In All Shopping App.

Some Function Is Applied On This App.

1) isApplicable($refObject = null, $eventName=' ')



"isApplicable" function is used to find whether the current app instance should be Started(triggered) for given event and reference object.


 If you want to decide to Starting(trigger) app as per event name then return true from here.

function isApplicable($refObject = null, $eventName='')
{
// return true for event onPayplansControllerCreation
if($eventName == 'onPayplansControllerCreation')
return true;
}
return parent::isApplicable($refObject, $eventName);
}

2) onPayplansControllerCreation($view, $controller, $task, $format)



"onPayplansControllerCreation" Function is Started(triggered) just before creation of controller instance.

eg. for which invoice the notification arrives. They can extract invoice key or payment key from the payment notification.

function onPayplansControllerCreation($view, $controller, $task, $format)
{
if($view == 'payment' && $task == 'notify')
$paymentKey = JRequest::getVar('invoice_num', null);
if($paymentKey){
$prefix = JString::substr($paymentKey, 0,3);
if($prefix !== 'PK_')
{
//get payment key from order key
$orderId = XiHelperUtils::getIdFromKey($paymentKey);
$order = PayplansOrder::getInstance($orderId);
$paymentId = $order->getParam('payment_id');
$paymentKey = XiHelperUtils::getKeyFromId($paymentId);
}
else
{
$paymentKey = JString::substr($paymentKey, 3);
}
JRequest::setVar('payment_key', $paymentKey, 'POST');
return true;
}


3)onPayplansPaymentForm(PayplansPayment $payment, $data = null)



In This Function Developer Can Choosed Payment GatewayTo Pay and Click On Checkout Option and Redirect To Other Page.This Page Will Be Decide To Developer Of The App.
function onPayplansPaymentForm(PayplansPayment $payment, $data = null)
{
$invoice = $payment->getInvoice(PAYPLANS_INSTANCE_REQUIRE);
$amount = $invoice->getTotal();
$this->assign('post_url', XiRoute::_("index.php?option=com_payplans&view=payment&task=complete&payment_key=".$payment->getKey()));
$this->assign('payment', $payment);
$this->assign('invoice', $invoice);
$this->assign('amount', $amount);
return $this->_render('form');
}

4)onPayplansPaymentAfter(PayplansPayment $payment, $action, $data, $controller)



This Function Is Publically.This Function Can Be Used To Fill Up The Data By The User.
function onPayplansPaymentAfter(PayplansPayment $payment, $action, $data, $controller)
{
if($action == 'cancel'){
return true;
}
if($invoice->isRecurring()){
//Will create recurring profile and then post the data to the payment gateway.
$this->_processRecurringRequest($payment, $data);
}
else {
//Will post the the data to the desired payment gateway.
$this->_processNonRecurringRequest($payment, $data);
}
$payment->save();
//calling of parent event is required to check whether
// there is any error during the above process.
return parent::onPayplansPaymentAfter($payment, $action, $data, $controller);


5) onPayplansPaymentNotify($payment, $data, $controller)



When Payment Notification is Received.This Function Can be Start.Processing Of Notification is Complete Means Verify Transtion is Sucessful pr Not.Zero Amount Can Be Display Error.

function onPayplansPaymentNotify($payment, $data, $controller)
{
$invoice = $payment->getInvoice(PAYPLANS_INSTANCE_REQUIRE);
// if its a recurring subscription
if(isset($data['x_subscription_id']) && $data['x_subscription_id'] ){
// get the transaction instace of lib
$transaction = PayplansTransaction::getInstance();
$transaction->set('user_id', $payment->getBuyer())
->set('invoice_id', $invoice->getId())
->set('payment_id', $payment->getId())
->set('gateway_txn_id', isset($data['x_trans_id']) ? $data['x_trans_id'] : 0)
->set('gateway_subscr_id', isset($data['x_subscription_id']) ? $data['x_subscription_id'] : 0)
->set('gateway_parent_txn', isset($data['parent_txn_id']) ? $data['parent_txn_id'] : 0)
->set('params', PayplansHelperParam::arrayToIni($data));
$errors = $this->_processNotification($transaction, $data, $payment);
$transaction->save();
return count($errors) ? implode("\n", $errors) : ' No Errors';
}
}

6) onPayplansPaymentTerminate(PayplansPayment $payment, $controller)



When Someone Is Terminated The Transtion Then This Function Is Start.
public function onPayplansPaymentTerminate(PayplansPayment $payment, $controller)
{
$transactions = $payment->getTransactions();
foreach($transactions as $transaction){
$subscriptionId = $transaction->get('gateway_subscr_id', 0);
if(!empty($subscriptionId)){
break;
}
}
$arbInstance->setRefId($payment->getKey());
$response = $arbInstance->cancelSubscription($subscriptionId);
$invoice = $payment->getInvoice(PAYPLANS_INSTANCE_REQUIRE);
$txn = PayplansTransaction::getInstance();
$txn->set('user_id', $payment->getBuyer())
->set('invoice_id', $invoice->getId())
->set('payment_id', $payment->getId())
->set('gateway_txn_id', isset($data['x_trans_id']) ? $data['x_trans_id'] : 0)
->set('gateway_subscr_id', $subscriptionId)
->set('gateway_parent_txn', isset($data['parent_txn_id']) ? $data['parent_txn_id'] : 0);
$txn->set('message', 'COM_PAYPLANS_PAYMENT_FOR_CANCEL_ORDER')->save();
return $this->_render('cancel_success');
}


0 comments:

Post a Comment

 
Toggle Footer