Reputation: 797
I want to submit gravity form to the hosted payment gateway "https://checkout.e-xact.com/pay" and I am using the code below.
I added below sample code in an active theme's function.php.
I want when the user submits the gravity form then form submits the necessary data through POST to this URL "https://checkout.e-xact.com/pay" then this page shows the data from the form and users can insert the payment information and submit the payment.
when I submit the form it shows the websites thank you page instead of submitting data to the "https://checkout.e-xact.com/pay" so users can insert the payment information and submit the form.
add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$post_url = 'https://checkout.e-xact.com/pay';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) );
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission: response => ' . print_r(
$response, true ) );
}
I really appreciate your help
Upvotes: 0
Views: 392
Reputation: 3241
There are various options of achieving what you looking for. The last time I had a similar situation I used the UI version though..
The Code you written above is absolutely correct, but it will not lead you to an external site, rather it will try to send the data to the service mentioned and finally display the thank you page of gravity forms.
In your case: You can simply go to your form Settings -> Confirmations, change the confirmation type to page redirect and check the option to submit fields in the query string, choose your fields and you are done.
Upvotes: 1