Skip to content
Docs
Get RestroPress

Action

rpress_gateway_{$gateway}

Updated
On this page

Fires to hand the purchase data to the gateway chosen at checkout.

Runs in rpress_send_to_gateway during checkout processing, with the gateway ID appended to the hook name. Built-in callbacks exist for paypal, manual, cash_on_delivery and stripe. A gateway callback should verify the gateway_nonce value against the rpress-gateway nonce action, record the payment, and then redirect the buyer.

Parameters#

ParameterTypeDescription
$payment_dataarrayPurchase data for the order, including a 'gateway_nonce' key to verify.

Example#

function my_gateway_process_payment( $payment_data ) {
	if ( ! wp_verify_nonce( $payment_data['gateway_nonce'], 'rpress-gateway' ) ) {
		wp_die( esc_html__( 'Nonce verification has failed', 'my-plugin' ), esc_html__( 'Error', 'my-plugin' ), array( 'response' => 403 ) );
	}
	$payment_id = rpress_insert_payment( array(
		'price'        => $payment_data['price'],
		'date'         => $payment_data['date'],
		'user_email'   => $payment_data['user_email'],
		'purchase_key' => $payment_data['purchase_key'],
		'currency'     => rpress_get_currency(),
		'fooditems'    => $payment_data['fooditems'],
		'user_info'    => $payment_data['user_info'],
		'cart_details' => $payment_data['cart_details'],
		'gateway'      => 'my_gateway',
		'status'       => 'pending',
	) );
	if ( $payment_id ) {
		rpress_empty_cart();
		rpress_send_to_success_page( '?payment_key=' . rawurlencode( $payment_data['purchase_key'] ) );
	} else {
		rpress_send_back_to_checkout( '?payment-mode=my_gateway' );
	}
}
add_action( 'rpress_gateway_my_gateway', 'my_gateway_process_payment', 10, 1 );

Notes#

The gateway ID in the hook name must match the key used when the gateway was registered with rpress_payment_gateways.

Source#

Fired from:

  • includes/gateways/functions.php (line 289), in rpress_send_to_gateway()

See also#

Was this page helpful?