1. Home
  2. Jobster
  3. Payment Gateways API v2
  4. Updating v1 to v2

Updating v1 to v2

This is a quick guide on how to update a custom made gateway from Gateways API v1 to Gateways API v2, which works with Jobster 4.0.0 and above.

 

Construct

1. Add $priority = 10 and $accepted_args = 2 to the following add_action calls from __construct():
add_action( 'wpjobster_taketo_' . $this->unique_slug . '_gateway',
								array( $this, 'taketogateway_function' ), 10, 2 );
add_action( 'wpjobster_processafter_' . $this->unique_slug . '_gateway',
								array( $this, 'processgateway_function' ), 10, 2 );

 

2. Add the following filter to the __construct() function:
add_filter( 'wpjobster_take_allowed_currency_' . $this->unique_slug,
								array( $this,'get_gateway_currency' ) );

 

3. Add the following function in your class, after __construct():
function get_gateway_currency( $currency ) {
	// if the gateway requires a specific currency you can declare it there
	// currency conversions are done automatically
	$currency = 'USD'; // delete this line if the gateway works with any currency
	return $currency;
}

 

Checkout

Starting with v2 we are passing the $common_details as a parameter to the checkout function and we also use a $payment_type parameter, which makes your gateway work with all the Jobster functionality without extra coding.

4. Add the $payment_type and $common_details parameters to taketogateway_function():
public function taketogateway_function( $payment_type, $common_details ) {

 

5. Remove the $common_details declaration from the taketogateway_function() since it is now passed as a parameter:
// delete the following line!
$common_details = get_common_details( $this->unique_slug, 0, $currency );

 

6. Add the $payment_type parameter to your return URLs as follows:
$all_data['success_url']  = get_bloginfo( 'url' ) . '/?payment_response=sample&payment_type=' . $payment_type;
$all_data['fail_url']     = get_bloginfo( 'url' ) . '/?payment_response=sample&action=fail&payment_type=' . $payment_type;

 

Processing

Starting with v2, based on the response that you get, you have 2 actions that you need to run and the rest of the work is done on our side.

7. Add the $payment_type and $details parameters to processgateway_function():
function processgateway_function( $payment_type, $details ) {

 

8. Remove the old code for success and failed transactions from processgateway_function():
// delete the following lines!
if ( $status == 'success' ) {
	$payment_status = 'completed';
	$payment_response = maybe_serialize( $_POST );
	
	wpjobster_mark_job_prchase_completed( $order_id, $payment_status, $payment_response, $payment_details );
	if ( get_option( 'wpjobster_sample_success_page' ) != '' ) {
		wp_redirect( get_permalink( get_option( 'wpjobster_sample_success_page' ) ) );
	} else {
		wp_redirect( get_bloginfo( 'siteurl' ) . '/?jb_action=chat_box&oid=' . $order_id );
	}
} else {
	$payment_status = 'failed';
	$payment_response = maybe_serialize( $_POST );

	wpjobster_mark_job_prchase_completed( $order_id, $payment_status, $payment_response, $payment_details );
	if ( get_option( 'wpjobster_sample_failure_page' ) != '' ) {
		wp_redirect( get_permalink( get_option( 'wpjobster_sample_failure_page' ) ) );
	} else {
		wp_redirect( get_bloginfo( 'siteurl' ) . '/?jb_action=chat_box&oid=' . $order_id );
	}
}

 

9. Add the new code for success and failed transactions in processgateway_function():
$payment_response = $serialise = maybe_serialize( $_REQUEST );

if ( $status == 'success' ) {
	$payment_details = "success action returned"; // any info you may find useful for debug
	do_action( "wpjobster_" . $payment_type . "_payment_success",
		$order_id,
		$this->unique_slug,
		$payment_details,
		$payment_response
	);
	die();
} else {
	$payment_details = "Failed action returned"; // any info you may find useful for debug
	do_action( "wpjobster_" . $payment_type . "_payment_failed",
		$order_id,
		$this->unique_slug,
		$payment_details,
		$payment_response
	);
	die();
}