paypal IPN and paynow button - paypal

I have a paypal button with the code in a file name paypaltest.php:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<!--<input type="hidden" name="custom" value="<?php //echo $id ?>">-->
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
I also have a paypal ipn php file name listener.php in the same location on my web hosting server directory.
I want to know how would i link the two to know if a transaction was Verified or not. Should i replace the sandbox url on the form with the listener.php file.

I can help you with single page PayPal pay now button
actually I use this one of my projects
<script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXXXXXXXXX">
</script>
<div id="paypal-button-container"> </div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '1230'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed');
// Call your server to save the transaction
return fetch('codes/paypalapi.php?invo=123', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
amount: data.amount
})
});
});
}
}).render('#paypal-button-container');
</script>

Related

Why post method does not work in blogger?

I have blogger website. I am making a contact form by editing HTML. But the post method doesn't work when I submit the form. It shows error "Method Not Allowed
Error 405".
Can anyone help me please?
<form name="google-sheet" method="post">
<h1>Registration</h1><br>
Your Name: <input type="text" name="name" required><br>
Your message: <input type="text" name="msg" required><br>
<br><br>
<button type="submit">Submit</button>
</form>
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycbzKqduyPdrNj2XMNKah5T2VJ92IFIRYkQx3w5uXazMc9ZSXCFCh/exec'
const form = document.forms['google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => alert("Your response has been recorded!"))
.catch(error => console.error('Error!', error.message))
})
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</body>
</html>

Transitioning from the old PayPal button to the PayPal Javascript SDK button

I have used the plain paypal button like this with no problems:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xxx#xxx.net">
<input type="hidden" name="item_name" value="Website Donation">
<input type="hidden" name="item_number" value="Donation">
<input type="hidden" name="amount" value="">
<input type="submit" value="Send Donation via PayPal" ><br></form>
and moved to this style to get Venmo and Credit card options:
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=secret&enable-funding=venmo&currency=USD" data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"Site Donation","amount":{"currency_code":"USD","value":1.99}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Full available details
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
// Show a success message within this page, e.g.
const element = document.getElementById('paypal-button-container');
element.innerHTML = '';
element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
},
onError: function(err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
I have a IPN page to receive the order information from the original button and it checks the item_name and item_number field from that.
My questions is, will the description (Website Donation) from the createOrder section translate to those same fields or will the description be a new field (what is it called)?
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"Site Donation","amount":{"currency_code":"USD","value":1.99}}]
});
},
In one of your sandbox Business accounts, set a sandbox IPN listener URL.
Create a REST app for that particular sandbox business account, and copy its client ID. Use that client ID to create a sandbox test payment, using a sandbox Personal account to approve the payment.
Log the data from the sandbox IPN you receive. It will have the available fields for that transaction.
I guess I could have tested it, but anyhow. I created a 1.99 butt and had someone use it. The "description" used in the new button came through with the field name of &transaction_subject=Site Donation&.

Adding a custom field in Paypal checkout

We are using Paypal checkout for our web app. We have the client lib where we are setting up the payment. In the back end, we are trying to capture the processed details via webhook. We tested this on a sandbox account. The webhook is sending all the details as expected except the custom field. We need the custom field in order to associate a payment with a certain service.
In our web app, we have the following:
paypalConfig = {
env: 'sandbox',
style: {
size: 'responsive',
color: 'white',
shape: 'rect',
label: 'pay',
layout: 'horizontal',
tagline: 'false'
},
client: {
sandbox: 'SANDBOX_ID',
},
commit: false,
payment: (data, actions) => {
console.log("data is", data, actions);
return actions.order.create({
payment: {
transactions: [
{ amount: { total: this.finalAmount * 100, currency: 'USD' }, job_id: this.jobId }
]
}
});
},
onApprove: (data, actions) => {
return actions.order.capture().then((details) => {
// This function shows a transaction success message to your buyer.
// alert('Transaction completed by ' + details.payer.name.given_name);
this.openModel('modal1');
}).catch(err => {console.log("Error in authorize in paypal", err); this.openModel('modal2');})
}
}
As you can see, the payment handler is adding a job_id property for the transaction object. In the back end, we are listening for the following events:
Checkout order completed, Payment capture completed, Payment sale completed
We only need to listen for an event (like Payment Received) that tells us when the transaction goes through. I wasn't sure so I added all events that seemed relevant because there wasn't any event named Payment Received.
Can this be done as we are trying here? We don't get the custom job_id field in the webhook.
First of all you appear to be using old PayPal checkout.js , switch to the newest sdk.js
Second of all you are using a client-side only integration, switch to a proper client-server pattern. Here is the front-end: https://developer.paypal.com/demo/checkout/#/pattern/server
You will need two corresponding routes on your server, 'Set Up Transaction' and 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
With the above solution, you have an immediate, synchronous API response on payment capture. There is no need for an additional asynchronous notification from webhooks, so those will essentially become superfluous to you.
Once all the above is working and creating successful transactions for you, there's one more thing to consider: propagating failures. That is, what happens in the case of an unhappy path, if the buyer's funding source fails to capture, e.g. their card is declined? There is a guide for how to send that error back to the UI, so they can add or choose a different card. Anyway, this is just the final detail to worry about.
Just create a paypal form and then add custom as one of the values. Heres an example. Also, here is a great tutorial to walk you through it https://youtu.be/HIwRzATH6iU
<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="amount" value="50.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="{MemberID}">
<input type="hidden" name="business" value="youremail#business.example.com">
<input type="hidden" name="item_name" value="Whatever Item">
<input type="hidden" name="item_number" value="600">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="return" value="https://www.yourwebsite.com/success/">
<input type="hidden" name="cancel_return" value="https://www.yourwebsite.com/failure">
<input type="hidden" name="notify_url" value="https://www.yourwebsite.com/ipn">
<input type="submit" value="Pay Now" name="submit" title="PayPal - The safer, easier way to pay online!" class="btn btn-primary">
</form>

i need to start setInterval when i submit a form using onsubmit

hi am trying to make setinterval work when i submit a form,
this what i have so far
setInterval(function(){ getUsers(); }, 1000);
`document.getElementById("cal").onsubmit =
function getUsers()
{
$.ajax({
url: 'test.php',
type: 'post',
success: function(data) {
$('.htmlelement').html(data);
}
});
}'
html
<FORM id= "cal" NAME="Calc" action="seller.php" method="post"
onsubmit="myFunction()">
<input type="text" name="firstname" value="Mickey"><br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="submit">
</FORM>
I think you have misunderstood how intervals should be wrapped. What you should do is wrap the submit button inside an interval and then make it call your function. You can use this fiddle http://jsfiddle.net/wauzpzdz/1/ for this purpose.

Prevent jQuery Ajax call if form is invalid using jQuery validate

I'm trying to use jQuery validate to validate a form and handle the form submission but can't seem to get the syntax correct and cannot find an example like mine in the API. My code is below:
$("#beta_form").validate({
rules: {
p_emailaddress: {
required: true,
email :true
}
}
submitHandler : function() {
$.ajax({
type:'POST',
url :'websiteUrlWithService',
data: $('#beta_form').serialize(),
complete: function() {
$('#dialog').jqmHide();
$('#formSubmissionThanks').jqmShow();
}
});
}
});
The form HTML is as follows:
<form class="login_form" id="beta_form" name="beta_form">
<label for="p_name" class="login_label">Name:</label>
<input type="hidden" id="p_enquiry" name="p_enquiry" value="Beta Enquiry" />
<input type="text" id="p_name" name="p_name" class="login_input" value="" />
<br />
<br/>
<label for="emailaddress" class="login_label">Email Address:</label>
<input type="text" id="p_emailaddress" name="p_emailaddress" class="login_input" value="" />
<br />
<br/>
<label for="role" class="login_label">Current Role:</label>
<select size="1" id="p_role" name="p_role">
<option value="1">None Selected</option>
<option value="2">Recruiter</option>
<option value="3">HR Role</option>
<option value="4">Self Employed</option>
</select>
<br/>
<br/>
<label for="terms" class="login_label">Include me in the Beta testing selection?</label>
<input type="checkbox" id="p_terms" name="p_terms" class="boxes login_label"/>
<br />
<br/>
<input type="submit" id="submitbuttonbeta" class="login_submitbutton" value="Submit" />
</form>
When I run this with Firebug on it suggests that I'm missing a } after the submitHandler property list but as far as I can see the syntax is correct. This error is preventing my form from firing altogether.
Any suggestions?
You were missing comma
$("#beta_form").validate({
rules: {
p_emailaddress: {
required: true,
email :true
}
},
submitHandler : function() {
$.ajax({
type:'POST',
url :'websiteUrlWithService',
data: $('#beta_form').serialize(),
complete: function() {
$('#dialog').jqmHide();
$('#formSubmissionThanks').jqmShow();
}
});
}
});
I think you're just missing a ',' after the rules object is defined, actually...
$("#beta_form").validate({
rules: {
p_emailaddress: {
required: true,
email :true
}
},
submitHandler : function() {
$.ajax({
type:'POST',
url :'websiteUrlWithService',
data: $('#beta_form').serialize(),
complete: function() {
$('#dialog').jqmHide();
$('#formSubmissionThanks').jqmShow();
}
});
}
});