3. Checkout

initializePayment( $payment_type, $order_details )

public function initializePayment( $payment_type, $order_details ) { // params from gateways/init.php

	// Payment ROW
	$payment_row = wpj_get_payment( array( 'payment_type_id' => $order_details['id'], 'payment_type' => $payment_type ) );

	// Callback URL
	$callback_url = get_bloginfo( 'url' ) . '/?payment_response=' . $this->unique_id . '&payment_id=' . $payment_row->id;

	if ( wpj_get_option( 'wpjobster_sample_id' ) && wpj_get_option( 'wpjobster_sample_key' ) ) {

		// User info
		$uid       = get_current_user_id();
		$user_info = get_userdata( $uid );

		// Action URL
		if ( wpj_get_option( 'wpjobster_' . $this->unique_id . '_enable_sandbox' ) == 'yes' ) $payment_url = 'https://sample.url';
		else $payment_url = 'https://test.sample.url';

		// Send data to Sample
		$fields = array();

		$fields['merchant_id']    = wpj_get_option( 'wpjobster_sample_id' );
		$fields['merchant_key']   = wpj_get_option( 'wpjobster_sample_key' );

		$fields['payment_id']     = $payment_row->id;
		$fields['order_id']       = $order_details['id'];

		$fields['job_title']      = apply_filters( 'wpj_gateway_order_title_filter', wpj_get_title_by_payment_type( $payment_type, $order_details ), $order_details, $payment_type, $this->unique_id );
		$fields['payable_amount'] = $payment_row->final_amount_exchanged;
		$fields['currency']       = $payment_row->final_amount_currency;

		$fields['success_url']    = $callback_url . '&action=paid';
		$fields['cancel_url']     = $callback_url . '&action=cancel';
		$fields['notify_url']     = $callback_url . '&action=notify';

		$fields['firstname']      = wpj_user( $uid, 'first_name' );
		$fields['email']          = wpj_user( $uid, 'user_email' );
		$fields['phone']          = wpj_user( $uid, 'cell_number' );
		$fields['lastname']       = wpj_user( $uid, 'last_name' );
		$fields['address']        = wpj_user( $uid, 'address' );
		$fields['city']           = wpj_user( $uid, 'city' );
		$fields['country']        = wpj_user( $uid, 'country_name' );
		$fields['zipcode']        = wpj_user( $uid, 'zip' );

		// Redirect to payment page
		wpj_display_gateway_form( $fields, $payment_url );

	} else { wpj_display_order_errors( $payment_type, __( 'Please fill Sample ID and Sample Key fields', 'wpjobster-sample' ) ); }
}

This function is hooked to the wpjobster_taketo_sample_gateway action, which is called when your gateway is used as payment method on the purchase page.

Usually here you create a form with all the info that you have about the merchant, order and user.
In our example the form is hidden and automatically submitted. It also has a spinning loader as a placeholder until the user is redirected to the gateway with all the necessary info.

$payment_type
(string) Is provided by the theme or from the plugin requesting the payment. For the gateway, you just need to use it in two places, in the actions for success and failed payment.

$order_details
(array) Contains all the info needed for sending the payment info to the gateway endpoint.

Example:

Array
(
    [id] => 60
    [payment_status] => pending
    [payment_gateway] => sample
    [payment_response] => 
    [payment_details] => 
    [date_made] => 1659209037
    [expected_delivery] => 0
    [date_finished] => 0
    [date_closed] => 0
    [pid] => 23612
    [uid] => 1
    [done_seller] => 0
    [closed] => 0
    [completed] => 0
    [done_buyer] => 0
    [mc_gross] => 34.000000
    [processing_fees] => 0.340000
    [site_fees] => 0
    [tax_amount] => 0.030000
    [admin_fee] => 0
    [notes_to_seller] => 
    [seller_confirmation] => 0
    [date_completed] => 0
    [extra1] => 0
    [extra1_price] => 0
    [extra1_title] => 
    [extra1_days] => 0
    [extra2] => 0
    [extra2_price] => 0
    [extra2_title] => 
    [extra2_days] => 0
    [extra3] => 0
    [extra3_price] => 0
    [extra3_title] => 
    [extra3_days] => 0
    [extra4] => 0
    [extra4_price] => 0
    [extra4_title] => 
    [extra4_days] => 0
    [extra5] => 0
    [extra5_price] => 0
    [extra5_title] => 
    [extra5_days] => 0
    [extra6] => 0
    [extra6_price] => 0
    [extra6_title] => 
    [extra6_days] => 0
    [extra7] => 0
    [extra7_price] => 0
    [extra7_title] => 
    [extra7_days] => 0
    [extra8] => 0
    [extra8_price] => 0
    [extra8_title] => 
    [extra8_days] => 0
    [extra9] => 0
    [extra9_price] => 0
    [extra9_title] => 
    [extra9_days] => 0
    [extra10] => 0
    [extra10_price] => 0
    [extra10_title] => 
    [extra10_days] => 0
    [extra_fast] => 0
    [extra_fast_price] => 0
    [extra_fast_days] => 0
    [extra_revision] => 0
    [extra_revision_price] => 0
    [extra_revision_days] => 0
    [custom_extras] => 
    [tips] => 
    [job_type] => daily
    [job_price] => 34.000000
    [job_amount] => 1
    [job_title] => Maecenas nec odio et ante
    [job_description] => Fusce fermentum odio nec arcu
    [job_instructions] => Phasellus magna. Nullam accumsan lorem in dui.
    [job_image] => 0
    [message_to_buyer] => 
    [message_to_seller] => 
    [request_cancellation_from_buyer] => 0
    [request_cancellation_from_seller] => 0
    [request_cancellation] => 0
    [force_cancellation] => 0
    [accept_cancellation_request] => 0
    [date_request_cancellation] => 0
    [date_accept_cancellation] => 0
    [request_modification] => 0
    [date_request_modification] => 0
    [message_request_modification] => 
    [clearing_period] => 0
    [date_to_clear] => 
    [shipping] => 0
    [payedamount] => USD|34
    [final_paidamount] => USD|34.37
)