4. Processing

processPayment( $payment_type, $payment_type_class )

public function processPayment( $payment_type, $payment_type_class ) { // params from gateways/init.php
	if ( isset( $_REQUEST['payment_id'] ) ) {
		$payment_id  = $_REQUEST['payment_id'];
		$payment_row = wpj_get_payment( array( 'id' => $payment_id ) );

		$order_id     = $payment_row->payment_type_id;
		$payment_type = $payment_row->payment_type;

		$payment_response = json_encode( $_REQUEST );
		$response_decoded = json_decode( $payment_response );

		// Save response
		$webhook = wpj_save_webhook( array(
			'webhook_id'       => $response_decoded->id,
			'payment_id'       => $payment_id,
			'status'           => $response_decoded->status,
			'type'             => $response_decoded->type,
			'description'      => $response_decoded->description,
			'amount'           => $response_decoded->total_amount,
			'amount_currency'  => $response_decoded->currency,
			'fees'             => 0,
			'fees_currency'    => $response_decoded->currency,
			'create_time'      => current_time( 'timestamp', 1 ),
			'payment_response' => $payment_response,
			'payment_type'     => $payment_type,
			'order_id'         => $order_id
		) );

		// Apply response to order
		if ( WPJ_Form::get( 'action' ) == 'cancelled' ) { // mark order as cancelled
			do_action( 'wpjobster_' . $payment_type . '_payment_failed', $order_id, $this->unique_id, 'Buyer clicked cancel', $payment_response );

		} elseif ( WPJ_Form::get( 'action' ) == 'paid' && $_POST['status'] == 'success' ) { // mark order as paid
			do_action( 'wpjobster_' . $payment_type . '_payment_success', $order_id, $this->unique_id, 'Transaction ID: ' . WPJ_Form::post( 'order_number' ), $payment_response );

		} else { // ipn
			if ( $_POST['status'] == 'success' )
				do_action( 'wpjobster_' . $payment_type . '_payment_success', $order_id, $this->unique_id, 'Transaction ID: ' . WPJ_Form::post( 'order_number' ), $payment_response );

			elseif ( $_POST['status'] == 'fail' )
				do_action( 'wpjobster_' . $payment_type . '_payment_failed', $order_id, $this->unique_id, 'Transaction ID: ' . WPJ_Form::post( 'order_number' ), $payment_response );

			else
				do_action( 'wpjobster_' . $payment_type . '_payment_other', $order_id, $this->unique_id, WPJ_Form::post( 'pg_txnid' ), $payment_response, $payment_status );

		}

	} else wpj_display_order_errors( $payment_type, __( 'Something went wrong! Payment ID is undefined!', 'wpjobster-sample' ) );
}

This function is hooked to the wpjobster_processafter_sample_gateway action, which is called when your gateway responds to the site with the payment status.

First of all you need to check if the answer from the gateway is successful. We also recommend checking if the amount paid is correct.

Then, based on the response that you get, you have 2 actions that you can run and the rest of the work is done on our side.