Tanuj Dutta
Tanuj Dutta

Reputation: 31

Integrating paypal button with a custom form and saving customer info into a database upon clicking that button

I have created an order form with a number of fields (codes are mentioned below). Now what I am trying to do is to integrate paypal's buy now button with this form! Since I am a novice here, I am not sure how to accomplish the same! As you can see, the form has a regular 'submit' button, which needs to be replaced with paypal's buy now.

Another important thing that I am trying to figure out is how to save the customer entered data into a database upon completion of the payment by clicking the buy now button. Any help would be appreciated.

My custom form:

<!-- FORM DIV STARTS HERE -->
<div id="order-form">
<form name="orderform" id="orderform" action="" method="">

<!-- PERSONAL INFORMATION BLOCK-->

<legend class="form-header">Personal Information</legend>
<fieldset class="order-form-line">
<span class="req">Name:*</span> <input type="text" name="customername" id="customername" class="required letterswithbasicpunc" style="margin-left:78px;"/><br />
<div class="help">Enter your full name such as "John Smith"</div>
<span class="req">Email:*</span> <input type="text" name="customeremail"  class="required email" style="margin-left:82px;" /><br />
<div class="help">Enter a valid email such as "[email protected]"</div>
Website: <input type="text" name="customersite" class="url" style="margin-left:72px;" />
<div class="help">Enter url like "http://www.yoursitename.com"</div> 
</fieldset>

<!-- ORDER INFORMATION BLOCK-->

<legend class="form-header">Order Description</legend>
<fieldset class="order-form-line">
<div class="formbuttons">
<span class="req new">Content Type:*</span>
<input type="checkbox" name="webcontent" class="required" /> Article
<input type="checkbox" name="webcontent" /> Review
</div>
<div class="formbuttons2">
<span class="req new">Content Tone:*</span>
<input type="checkbox" name="contenttone" class="required" /> Professional 
<input type="checkbox" name="contenttone" /> Friendly
</div> 
Keyword(s): <input type="text" name="keys" class="" style="margin-left:51px;" /><br />
<div class="help">You can enter keywords in a comma-separated format</div>
Description: <div class="areatxt"><textarea rows="5" cols="31">Your description goes here</textarea></div>
<div class="help">Describe if you have any other requirements</div>
Audience: <input type="text" name="audience" class="" style="margin-left:66px;" />
<div class="help">You can provide info on your target audience</div>
</fieldset>

<!-- PAYMENT DETAILS BLOCK -->

<legend class="form-header">Payment Details</legend>
<fieldset class="order-form-line modified">
<span class="req">No. of Words:*</span> <input type="text" name="wordsno"  id="wordsno"  class="required digits" value="0" style="margin-left:31px; text-align:center;" /> <br />
<div class="help">Enter (only digits) your per word requirement such as "500" for  five-hundred word articles</div>
<span class="req">Quantity:*</span> <input type="text" name="wordsqty" id="wordsqty" class="required digits" value="0" style="margin-left:60px;text-align:center;" /> <br />
<div class="help">Enter (only digits) the total number of articles you need such as "10" for ten articles</div>
 Unit Price: <input type="text" name="wordsunitprice" value="$0.02" disabled="disabled" style="margin-left:64px;text-align:center;" /><br />
<div class="help">This is the "per word" cost</div>
Total Cost: <input type="text" name="wordstotalcost" id="wordstotalcost" value="$0.00" disabled="disabled" style="margin-left:59px;text-align:center;" /><br />
<div class="help">This reflects the total amount you would have to pay. It multiplies the 'unit price' with the result we get multiplying 'no. of words' and 'quantity'</div>
<input type="submit" value="Submit" />



</fieldset>
</form>
</div><!-- FORM DIV ENDS HERE -->

So my exact questions are:-

(1) How would one replace the regular html submit button of a custom form with a paypal buy now? Note: The 'amount to be paid by the customer' is going to pass dynamically to paypal's buy now.

(2) What would one do if he wants to save entire customer info into a database? This should happen upon receipt of payment confirmation from paypal's end!

Upvotes: 1

Views: 3037

Answers (1)

Drew Angell
Drew Angell

Reputation: 26056

If you want to keep things as simple as possible, I'd go with PayPal Payments Standard. You can either create Buy Now button code from within your PayPal account under the Merchant Services tab, or you can use the Cart Upload method and build it yourself, which is what I would recommend.

Basically, you'll just create a new form with a bunch of hidden fields to represent data you'll send to PayPal and then you can use whatever type of submit button you want. PayPal provides a list of all the standard variables you could use with this.

To get order data into your own database (or send customized email receipts, interact with 3rd party web services, etc.) I would recommend using Instant Payment Notification (IPN). This system POSTs all transaction data to a listener script you have sitting on your server. You can process this data however you want, and it all happens in real-time.

Upvotes: 1

Related Questions