How to integrated payment gateway in my form - php

Really I am confused how to start..
I have a submit form in my webpage. which contains name, address, email etc. along with Amount To Be Paid (fetched from mysql database).
Now I want user to redirect to payment gateway with amount ((which is not fixed, but changing) and ONLY after successful payment, the form should be get submitted and data should be get added to mysql database.
I have downloaded Instamojo payment gateway api details and I already have active account on Instamojo.
My current code for Submit Form is as follows...
<?php
include("db.php");
if($_POST['action']=="registration"){
$all_columns[]="fname";
$all_columns[]="mname";
$all_columns[]="lname";
$all_columns[]="email";
$all_columns[]="amount_paid";
$all_values[]=addslashes($_POST["fname"]);
$all_values[]=addslashes($_POST["mname"]);
$all_values[]=addslashes($_POST["lname"]);
$all_values[]=addslashes($_POST["email"]);
$all_values[]=addslashes($_POST["amount_paid"]);
$qry=$estambha->webdreaminsert("registration",$all_columns,$all_values,'','','');
$_SESSION["Register_id"]="suceess";
header("location:registration-confirm.php");
}
?>
And HTML Form code is as follows :
<form name="registration_form" id="registration_form" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="registration" />
Name :<br />
<label for="fname">First Name :</label> <input name="fname" type="text" id="fname" required/>
<label for="mname">Middle Name :</label> <input name="mname" type="text" id="mname" required/>
<label for="lname">Last Name :</label> <input name="lname" type="text" id="lname" required/>
<br />
<br />
E-mail :<br />
<input name="email" type="text" id="email" required/>
<br />
<br />
Registration Amount:<br />
<?
$paymentdata=mysql_query("select * from event_calendar where branch='Nk' group by part DESC limit 1");
$numrows1=mysql_num_rows($paymentdata);
while($amount=mysql_fetch_array($paymentdata)){?>
<input type="text" id="amount_paid" name="amount_paid" value="<?=$amount['fees_for_online']?>" readonly="readonly" />
<? }?>
<input name="formsubmit" type="submit" id="inputsubmit1" value="Register Me" />
Currently After Form Submission, Data get added to mysql database. But I want To Redirect user to Instamojo Payment Gateway Page with Amount from readonly field and after successful payment, user should redirect to registration-confirm.php page and during this data should be get added to mysql.
I am not getting any idea how to do this. I went through Instamojo documents too...Till searching for solution...

ok, let me start with the simple basic process which is followed by all payment integration modules (Process is based on authorized and paypal payment gateway).
1) Collect the data required you payment like user information and payment details like amount and quantity.
2) Payment gateway provides a form which need to be submitted on their sandbox account (URL given in documentation). you can submit the form either CURL or by simple jquery form submit. If you are using jQuery then form must be generated on runtime.
3) In the form provided by the payment gateway, there are two URL success url and the fail url. When the user transaction is complete depends on result, payment gateway redirect to your site on either URL.
4) Get the responce return by payment gateway on relevant success or fail page and process the data.

Related

NAB Transact hosted payment page doesn't trigger reply_link_url

I'm using hosted payment page, here system redirects to nab transact page for payment and displays receipt page after transaction approved.
I set the return_link_url and reply_link_url in input hidden variables as below.
<form action="https://demo.transact.nab.com.au/live/hpp/payment" method="post" id="payment">
<input type="hidden" name="vendor_name" value="XXXXXXX" />
<input type="hidden" name="payment_alert" value="xx#xx.com.au" />
<input type="hidden" name="print_zero_qty" value="false">
<input type="hidden" name="return_link_text" value="Click Here to Return to the Home Page">
<input type="hidden" name="return_link_url" value="http://www.mysite.com.au/index.php?route=payment/nabtrans/callback&order_id=51216" />
<input type="hidden" name="reply_link_url" value="http://www.mysite.com.au/index.php?route=payment/nabtrans/callback&order_id=51216" />
<input type="hidden" name="Pay for Order number 51216" value="22" />
<input type="hidden" name="payment_reference" value="51216" />
<input type="hidden" name="Name" value="XXX XX" />
<input type="hidden" name="information_fields" value="Name">
The problem is the reply_link_url is not getting triggered automatically at the time payment receipt page is displayed to customer as mentioned in guide.
I tried with appropriate cgi handler which does executes if called. So, I used them in the reply link url, but still the link doesn't triggered automatically.
<input type="hidden" name="return_link_url" value="http://www.mysite.com.au/cgi-bin/handler.cgi?orderid=51217" />
<input type="hidden" name="reply_link_url" value="http://www.mysite.com.au/cgi-bin/handler.cgi?orderid=51217" />
I have to click on return link on payment receipt page to come back to website. The reply_link_url never triggered automatically after the receipt page displayed in 15 sec timeout. I made sure to use http in reply link url to make it listening on port 80. The CGI script executes if I run it in browser.
Solved
I used two different url's for reply_link_url and return_link_url.
They are
<input type="hidden" name="return_link_url" value="http://www.mysite.com.au/index.php?route=payment/nabtrans/replyback&order_id=51216" />
<input type="hidden" name="reply_link_url" value="http://www.mysite.com.au/index.php?route=payment/nabtrans/callback&order_id=51216" />
I made sure to add the code inside callback function to execute the background process after payment approves and used code for redirecting to payment success page inside replyback function. Both these functions reside in nabtrans controller. As I noticed the the reply link triggers automatically which executes the background processes to update order, but the last step of displaying the checkout/success page never bring the link from payment success page of nabtrans to the original website. Still I was happy all background tasks done. So, I used the return link for coming back to original website. This solves the purpose completing transaction and coming back to website.

Publish user submitted post after payment

I'm using a plugin called USP Pro which allows users to publish posts on my Wordpress Site. Upon pressing the submit button to publish their post, the user is redirected to PayPal(whilst their submitted post is sent to my wordpress posts section to be reviewed and 'published'). However, if the user doesn't pay the fee their post will still be submitted, which needs to be prevented. I initially overcame this problem by redirecting the user to the PayPal page for payment before the submit button stage, and then redirecting them back to the form afterwards to press the submit button (which involved echoing the form inputs). However, the form includes file uploads which cannot be sent across multiple pages due to security restrictions, so the PayPal page has to be after the submit button is pressed.
Here is my form:
<form id="usp-form-990" class="usp-form" method="post" enctype="multipart/form-data" action="" data-validate="parsley" data-persist="garlic" novalidate>
<input name="usp-title" type="text" value="" data-required="true" required="required" maxlength="99" placeholder="Post Title" class="usp-input usp-input-title" />
<input name="usp-title-required" value="1" type="hidden" />
<textarea name="usp-content" rows="5" cols="30" maxlength="999" data-required="true" required="required" placeholder="Post Content" class="usp-input usp-input-content"></textarea>
<input name="usp-content-required" value="1" type="hidden" />
<input name="usp-files[]" type="file" maxlength="255" data-required="true" placeholder="File(s)" class="usp-input usp-input-files select-file multiple" multiple="multiple" id="usp-multiple-files" />
<input name="usp-file-limit" class="usp-file-limit" value="20" type="hidden" />
<input name="usp-file-count" class="usp-file-count" value="1" type="hidden" />
<input name="usp-files-required" value="0" type="hidden" />
<input type="submit" class="usp-submit" value="Publish" />
</form>
Here is the PayPal button that is used:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5F498FHQQGRR2">
<input type="image" src="http://www.aeroex.co.uk/wp-content/themes/vantage/paybutton.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
I don't know if this will help, but I found this code to prevent this exact issue but for another forms plugin called Formidable Pro. Due to my inexperience with PHP and coding in general, I have found myself unable to customize this code to suit my requirements.
add_action('frm_payment_paypal_ipn', 'publish_paid_post');
function publish_paid_post($args){
if(!$args['pay_vars']['completed'])
return; //don't publish if the payment was not completed
if(!$args['entry']->post_id)
return; //don't publish if not linked to a post
wp_update_post(array('ID' => $args['entry']->post_id, 'post_status' => 'publish'));
}
My other attempts to solve this:
-saving user file uploads to wordpress directory and then retrieving them at the submit stage (unsuccessful)
I would suggest the flow to be: Put every thing user submitted with a "Draft" status, and implement an IPN(Instant payment notification) script to read PayPal payment call-backs, then update the WP database to change the post status from "Draft" to "Published"
The payment return/redirection should not be relied on in this case as when client browser is closed before auto-return, the process breaks. While IPN is the async message POST for a payment status, that's something you should use for processing the USP posts.
Not sure if there's any setup available in the USP Pro plugin but here's an sample IPN script which you may customize with your WP database update codes.
Formidable Pro has a PayPal extension that will do this. You build your user-submission form, then in form settings you add a PayPal action and fill in the necessary details. You also add a 'Create Post' action and use the conditional logic options to only publish if the payment is successful.

2 form actions in interspire email marketer

My client is using interspire email marketer, which generate html form, and save all data into crm database.
In the form, there is a postcode area, my client wants to send email alert to different department based on this postcode.
I am thinking to create a seperate php file to match the postcode and send email alert.
But there is already a form.php in action. How can I add another action? Or is there any better way to achieve this?
Many Many thanks.
Below is the form code:
<form name="ppt_form" class="ppt-form" method="post" action="http://na03.mypinpointe.com/form.php?form=332" id="frmSS332">
<p><span class="required">*</span>Your Email Address:<br />
<input type="text" class="email" name="email" fid="e" fname="Email" ftype="Email" reqd="1"/></p>
<p>Phone:<br />
<input type="text" name="CustomFields[8]" id="CustomFields_8_332" value="" fid="8" fname="Phone" size='50'></p>
<p>Postal: <br />
<input type="text" name="CustomFields[20]" id="CustomFields_20_332" value="" fid="20" fname="Postal" size='50'></p>
<p><input type="button" class="update-button" value="Submit"/></p>
</form>
Eventually I leave the form with 1 action.
and add a ajax on button click.

Multiple web service requests from single page in html

I am trying to submit three forms in single page. But I stuck at one point.
I want to make verification of mobile Number in first Form. then use that Mobile Number in final Form submission
I have tried using this in single Form but then How can I send web request for sending verification pin with verify Mobile Button.
I have Three forms like this,
//First Form Take Mobile Number, web service will send verification Pin as reply to this action
<form name="PhoneVerification" action="url to phone verification web service" >
Phone Number: <input type="text" name ="number" id="phone">
<input type="submit" name ="submit1" id="submit1">Verify Mibile Number</input>
</form>
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin came from previous web service">
Verification Pin(Sent on Mobile Number): <input type="text" name ="pin" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
//Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
The Problem is I am not able to get value of phone number as page is refreshed after that Form submission.
I read some threads about using AJAX , But How can I use Ajax in this type Of situation.
How can I achieve this. with AJAX, or using PHP.
Id must be unique in your html page. In above code id="phone" be present in first to forms. the second form in pinVerfication right but there is an same id = "phone" . please change it and make an another try. third form have also same problem
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin">
Verification Pin(Sent on Mobile Number): <input type="text" name ="number" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
/Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
You can use cookies or sessions to achieve this task.
if you want to do it with only javascript, you can use cookies. you can get the best reference from w3schools
You can do it with server side script like php and use ajax.
In this case you can use session.
First form submission store number in cookies or session. and in another form you get that value from cookie or session and make use of it.
Note: Don't forgot to delete cookies or session after you finish all work.

How to integrate FirstData as payment gateway?

I want to integrate FirstData as my payment gateway.
How to start with this?
I am using php.
Thanks
Code which i have used
<? include("ipg-util.php"); ?>
<form method="post" action="https://test.ipg-online.com/connect/gateway/processing">
<input type="hidden" name="txntype" value="sale">
<input type="hidden" name="timezone" value="GMT"/>
<input type="hidden" name="txndatetime" value="<?php echo getDateTime() ?>"/>
<input type="hidden" name="hash" value="<?php echo createHash(13.00,978) ?>"/>
<input type="hidden" name="storename" value="1909354791"/>
<input type="hidden" name="mode" value="payonly"/>
<input type="text" name="chargetotal" value="13.00"/>
<input type="hidden" name="currency" value="978"/>
<input type="submit" value="Submit">
</form>
Quite old post, but might be useful for others.
The documentation of First Data Payment Gateway is available here.
Once your form is set up with your store name and other required information, don't forget to set up the connection settings in your Global Gateway Virtual Terminal account:
Production link: https://www.linkpointcentral.com
Test link: https://www.staging.linkpointcentral.com
To do so, go to Administration > Connect Settings, then insert in Submission Form URL the URL of the page from which you call the payment service, and the response URLs...
Hope it helps.
Yes Guillaume.M you are right.
Actually had a problem while integrating the connect, then i contacted support then they told me that the Submission Form URLs are required to do the payment successfully!..
Submission URL are basically the success or thank you page and failure page url.
In the manual avaiable on the telecash documentcenter, they did not added the URL settings step in mandatory..
Then i emailed them, they accepted the suggtion..
Thank you

Categories