How to integrate new Payment Gateway into JobEngine & ClassifiedEngine

Updated on November 14, 2024 in No Category
0 on January 20, 2015

First, we need to add a checkout button, we can add it before or after JobEngine or ClassiFiedEngine default checkout buttons.

Example, I add Stripe checkout button:

JobEngine: add_action ('after_je_payment_button', 'stripe_payment_button');
ClassifiedEngine: add_action ('after_ce_payment_button', 'stripe_payment_button');
function stripe_payment_button ($payment_gateways) {
	if(!isset($payment_gateways['stripe']))  return;
	$stripe	=	$payment_gateways['stripe'];
	if( !isset($stripe['active']) || $stripe['active'] == -1) return ;
?>	<li class="clearfix">
	<div class="f-left">
		<div class="title"><?php _e( 'Stripe', ET_DOMAIN )?></div>
		<div class="desc">
<?php _e( 'Pay using your credit card through Stripe.', ET_DOMAIN )?></div>
		</div>
		<div class="btn-select f-right">
		<button id="stripe_pay" class="bg-btn-hyperlink border-radius" data-gateway="stripe" >
<?php _e('Select', ET_DOMAIN );?>
</button>
	</div>
	</li>
	<?php
	}

Note: $payment_gateways is array of enabled gateways.

payment

When user checkouts for a job, JobEngine has 2 steps to process payment.
First step, send payment details, set up the payment and send a response to client. After client receive reponse, use javascript to submit user to payment processor. To filter the response we can use filter ‘ je_payment_setup’:

JobEngine: add_filter ('je_payment_setup', 'setup_payment');
ClassifiedEngine: add_filter (‘et_payment_setup', 'setup_payment');

function setup_payment ( $response , $paymentType, $order ) { 
	// your payment setup and return reponse here
}
$response : payment response for setup a payment
$paymentType: payment gateway type, use to check which payment gateway is used
$order : order information 

Second step, when users submit a payment, and already pay for a job. They will be returned to page process payment to approve payment or deny fraud. In function process payment return has a filter-‘je_payment_process’ to help developer process integrated gateway.

Here is the function filter and process payment by stripe:

JobEngine: add_filter( 'je_payment_process', 'process_payment', 10 ,2 );
ClassifiedEngine: add_filter( 'et_payment_process', 'process_payment', 10 ,2 );
function process_payment ( $payment_return, $order) {
	if(isset($_REQUEST['paymentType']) && $_REQUEST['paymentType'] == 'stripe' ) {
		if($_REQUEST['token'] == $order->get_payment_code() ) {
			$payment_return	=	array (
				'ACK' 		=> true,
				'payment'	=>	'stripe'
			);
			$order->set_status ('publish');
			$order->update_order();
			}
		}
		return $payment_return;
	}

Tip: you can use ‘je_payment_settings’ and ‘et_update_payment_setting’ hooks render and save payment gateway settings.

 
  • Liked by
Reply