I have used the following code for PayPal subscribe button, from the sandbox.paypal.com:-
<div id="paypal-button-container-P-86B16126YE351481NMH6WMRY"></div>
<script src="https://www.paypal.com/sdk/js?client-id=AT4fx8CxfLze4ZzMRrp-yUZBlKQvFt97cMDgzUwqXBpbvPSw7w0EmoLBk1zJw7PddEDRD_HJ05y4qjh5&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'pill',
color: 'silver',
layout: 'horizontal',
label: 'subscribe'
},
createSubscription: function (data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'P-86B16126YE351481NMH6WMRY'
});
},
onApprove: function (data, actions) {
alert(data.subscriptionID); // You can add optional success message for the subscriber here
}
}).render('#paypal-button-container-P-86B16126YE351481NMH6WMRY'); // Renders the PayPal button
</script>
But, when clicking this button from the website (where I put this button code) and logging into the PayPal sandbox for the payment, it shows the following error message:-
Sorry, we couldn't set up your subscription using the payment method you selected. Please try another payment method.
I have tried all the available payment methods for my sandbox account(where from I am trying to subscribe). But nothing worked. I have been trying it for the last couple of hours, but it is not working.
Review your list of sandbox accounts, log into this button's account via www.sandbox.paypal.com and go to its email settings. Resend a confirmation "email" if necessary--sandbox doesn't send real email messages.
Read the confirmation "email" in the "Notifications" side tab of the developer dashboard, and use the link there to confirm it.
Retry your subscription payment after having confirmed the receiving sandbox account's primary email.
Related
Hi I have successfully Integrated PayPal Checkout Smart Payment Buttons, where i am using custom payee reference https://developer.paypal.com/docs/checkout/integration-features/custom-payee/
My point is if the custom payee email is invalid still the payment completes and the fund goes to the account of the API credentials owner. But I don't want that. IF custom payee email is wrong the payment should not be successful, it must throw a error with proper message so i can catch the error.
I didn't get any solution from paypal docs.
if the custom payee email is invalid still the payment completes and the fund goes to the account of the API credentials owner
What do you mean by 'invalid'? Please be specific about your meaning.
If the email is not associated with an existing PayPal account, the payment will be in a pending state. The owner has 30 days to create a PayPal account using that email (or add it to an already existing PayPal account) and accept the pending payment. If they do not do so within 30 days, the payment will be automatically refunded. In this scenario, it is not the case that "the fund goes to the account of the API credentials owner". That is not happening.
Now, if you are trying to pass a payee object at payment setup time with a blank / empty string email_address, then it will just be ignored, and the payment will go to the API credentials owner as per normal payment processing w/o a custom payee.
So, you need to do your own validation to ensure the payee field is non-blank. You could simply check that it is a non-empty string.
Or, do one better, and actually check that it is an email address in a valid format:
function isEmail(y) {
var re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(y).toLowerCase());
}
If it is not valid, you should not allow the order creation to proceed using that non-valid custom payee, since it will obviously not create the transaction you wish. Instead, you should display an error that the checkout is not set up properly for this user/recipient/payee.
<script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXX"></script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '1.00'
},
payee: {
email_address: 'someemail#somedomain.com'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
//success
},
onCancel: function (data) {
//cancel payment
}
}).render('#paypal-button-container');
Here the payee email is not exists and fund goes to api owner
I'm trying to integrate PayPal subscriptions using Smart Buttons in JavaScript with sandbox app & account.
paypal.Buttons(
{
style: {
layout: 'horizontal',
size: 'small',
color: 'gold',
label: 'paypal',
height: 35,
tagline: 'true'
},
createSubscription: function (data, actions) {
return actions.subscription.create({
'plan_id': 'P-xxxxxxxxxxxxxxxxxxxxxxxx'
});
},
onApprove: function (data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID);
}
}
).render('#paypal-button-container');
After new window opens up I login with my sandbox bussiness account. The spinner appears and after a while I get a message "Something went wrong". I checked webhook and subscription is successfully created, but when PayPal navigates to checkout to approve it, the above happens.
I tried to use Subscriptions API and I made a call using Postman to create subscription. Then in response I recieved url to approve subscription. I opened it, logged in, this time I had to choose PayPal or Credit/Debit Card and again, spinner, some time passes and message appears saying "Something went wrong."
I checked wether encryption settings are disabled, cause I found it might cause issues, but it was disabled by deafult.
I also tried passing the whole subscription object from docs, not just "plan_id", but it changed nothing.
Don't have any other ideas what might went wrong. I hope someone stumbled upon this issue, found the solution and is willing to share it :D
We are integrating the PayPal client side Checkout Integration for taking payments on our website. This can be found here:
https://developer.paypal.com/docs/checkout/integrate/#6-verify-the-transaction
Once the payment has been made and approved by PayPal, we need to call our server to verify the transaction and store it within our database. This code can be found below, note the part "Call your server to save the transaction".
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/paypal-transaction-complete', {
method: 'post',
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');
</script>
Now, in the above instance, what happens if the call to "/paypal-transaction-complete" fails? session timeout or lost internet connection? For example, in the Stripe integration, the money is "approved" in on the client side and then only confirmed/charged in our API to "/stripe-transaction-complete". If there is an error, we don't actually charge the money.
Within PayPal, the money is charged before the API call, so the is the small possibility we charge the user but they don't receive the paid order in the database. How would we best handle this? one option would be to call the PayPal API and match all the orders with payments and then either auto-refund or auto-complete the order. But I'm not sure if this is recommended.
For both PayPal and similar issues with Stripe Checkout, this can be addressed using WebHooks.
https://developer.paypal.com/docs/integration/direct/webhooks/rest-webhooks/#
I am building a really simple payment form where the user can enter an amount and a thank you message. I have got it successfully working with just the amount but I cannot get add a message field and get it to come through!
Here is just the payment function of my JavaScript:
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: window.transactionAmount,
currency: 'GBP'
},
note_to_payee: document.getElementById('custom-message').value,
description: 'A gift to Martin.',
custom: 'This is a test custom field',
payee: {
"email": "martin#[hidden].com"
}
}
]
},
experience: {
input_fields: {
no_shipping: 1,
allow_note: true
}
}
});
},
I have tried setting custom and note_to_payee but neither seem to be recorded on either the notification email or the data that is logged in the recipient's account.
I have also tried turning on the ability for the payer to add a note by setting allow_note: true in the experience config but that does nothing!
Please help, just any way of passing through a little message with the payment is all I need.
It took PayPal Support team 4 days to come back with the answer that No, it cannot be done.
Here's their full response:
With regard to your request, I have to inform you that "note to seller" (allow_note:true) field is only available in the older PayPal payment experience, and is not available in the newer payment experience.
Unfortunately, there's nothing the caller can do at this time to force an old or new experience and we recommend to collect this information in your website where possible.
So it looks like they've dropped one of the nicest and most simple features of the PayPal checkout which was the ability to include a friendly little note.
Now, my only option is to build a whole back-end system with API end-points and extend my JavaScript just to record my payer's note. Meanwhile, every email notification I receive will continue to contain that annoying lie: "The buyer hasn't entered any instructions".
PayPal: Please, either implement a feature in your new process or remove/hide the feature! Don't do a half-way job. You take 10% of all my transactions, I expect better.
A workaround for this would be to use an "option variable" to create a textbox in your checkout flow. An example of an option variable would be "os0" and "on0".
Here is an example on our website on how you would implement this: https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_options_help_outside
https://developer.paypal.com/sdk/js/reference/#onapprove
paypal.Buttons({
createOrder: function(data, actions) {
...
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer
alert('Transaction ' + transaction.status + transaction.id);
window.location.href = 'https://www.yoursite.com/page.php?trnsid='+ transaction.id;
});
}
}).render('#paypal-button-container');
You can do a redirect onApprove.
If the transaction was completed redirect the user to a page with a FORM THAT GET/capture the transactionID (associate the message with a transaction) and ADD a MESSAGE TEXTAREA so user can send some notes after payment.
How can I trigger PayPal Checkout button click?
We have a website were beside the Credit Cards we are going to accept also PayPal payments and I have decided to put radio buttons for the customers to choose which way the customer is going to pay and also PayPal Checkout button:
PayPal Checkout button click itself opens the PayPal secure window and the rest works fine. When customer click the 1st radio button I want again open PayPal secure window i.e. trigger click on PayPal checkout button.
How can I do that if the button itself appearing in iframe and I am not able to trigger click event of that button cross domain? Is there any way to trigger checkout button click?
Here is the HTML code:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script type="text/javascript" src="paypal.js">
</script>
<body>
<div>
<span style="vertical-align: 50%"><input id="rd" name="aaa" type="radio"/></span>
<div id="paypal-button-container" style="display: inline-block"></div><hr/>
<input id="rd1" name="aaa" type="radio"/>
</div>
</body>
</html>
And Javascript code:
// paypal.js
// Render the PayPal button
$(function(){
paypal.Button.render({
// Set your environment
//TODO: Dynamically provide sandbox or production
env: 'sandbox', // sandbox | production
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
//TODO: Dynamically provide clientID
client: {
sandbox: 'ZZZZZZ',
production: '//TODO: Provide this later'
},
// Wait for the PayPal button to be clicked
payment: function() {
// Make a client-side call to the REST api to create the payment
return paypal.rest.payment.create(this.props.env, this.props.client, {
transactions: [
{
amount: { total: '13.10', currency: 'USD' }
}
]
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
return actions.payment.get().then(function(paymentData) {
$('#paypal-button-container').style.display = 'none'; //hide button
//TODO: Show user payment details
//TODO: Create input hidden fields and set payerID, paymentID, etc..for later authoriza/capture
});
},
onClick: function(){
$('#rd').trigger('click');
},
}, '#paypal-button-container');
});
EDIT: As a working example I would suggest this site, but this is little bit different what I need https://developer.paypal.com/demo/checkout/#/pattern/mark
This isn't something that's supported by the PayPal button right now. The official policy is, only a click on the button itself should open a checkout window.
I guess I am a little bit late, but I hope this will help people who faced this problem, just like me.
You can set paypal's button opacity to 0 and put it over your own checkout button. Then you can set it's display to 'none' or 'block' depending on radio button value.
In my case, I just wanted to use a completely customized button for space reasons. In the end, I hid the paypal button until it on mouse over wrapped in an overflow:hidden div. It looks ok - like a square paypal button without left/right padding..
Background: Paypal's current express checkout documentation says they only support buttons at 80px minimum size, but playing with CSS, seems like the real minimimum on desktop is appx 120px wide.
First of it need to clear what you are using.
Checkout js then checkout with checkout.js. Valid before February 2019.
JavaScript sdk then there is no official announcement from paypal, if anyone do reverse engineering then would be possible.
It's literally not supported. You can't programmatically click on paypal button.
Please visit for more clarification: https://github.com/paypal/paypal-checkout-components/issues/512