paypal Javascript Integration - What's form Action Parameter? - paypal

What is "/checkout" in the below line ?. Actually it referring localpath.
Can you please suggest me the appropriate action URL ?
Also, Can you suggest me where do I give the IPN URL / Syntax ?
<form id="myContainer" method="post" action="/checkout"></form>
<script>
window.paypalCheckoutReady = function () {
paypal.checkout.setup('<Your-Merchant-ID>', {
environment: 'sandbox',
container: 'myContainer'
});
};
</script>
[paypal Integration] https://developer.paypal.com/docs/classic/express-checkout/in-context/integration/
Thanks,
Raja K

This describes it:
A basic Express Checkout integration assumes that you are sending the
API calls from your own server using a <form> or <a>.
Essentially, your existing call to SetExpressCheckout (that would obtain a Paypal token) that you use to redirect (in the "standard" Paypal Express Checkout flow).
The linked sample should hopefully clear things up - you'll see the form action (and a link) POST (GET for the a) to some server implementation (the ip address in the sample) of SetExpressCheckout.
Hth..

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>
change codes/paypalapi.php?invo=123 with your callback url

Related

Getting console errors while setting up client to call server side PayPal API

While setting up, PayPal client code to test server integration, from https://developer.paypal.com/docs/archive/checkout/how-to/server-integration/
My code is as follows:
<html>
<head>
<title>TEST PAYMENT</title>
</head>
<body>
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
env: 'sandbox', // Or 'production'
// Set up the payment:
// 1. Add a payment callback
payment: function(data, actions) {
// 2. Make a request to your server
return actions.request.post('/api/paypal/create-payment')
.then(function(res) {
console.log(res);
// 3. Return res.id from the response
return res.id;
});
},
// Execute the payment:
// 1. Add an onAuthorize callback
onAuthorize: function(data, actions) {
// 2. Make a request to your server
return actions.request.post('/api/paypal/execute-payment', {
paymentID: data.paymentID,
payerID: data.payerID
})
.then(function(res) {
// 3. Show the buyer a confirmation message.
});
}
}, '#paypal-button');
</script>
</body>
</html>
When I open the page.
When I click the button, a modal window shows up for a second and closed with the following errors.
The checkout.js integration you're attempting to use is deprecated.
Here is the current JS SDK to call your server with: https://developer.paypal.com/demo/checkout/#/pattern/server

PayPal Checkout JS SDK onError not triggering when cards not processed

I am trying to redirect customers to an error page for my website if their card cannot be processed. It not working and all I can get is the standard PayPal alert that says "Things don't appear to be working at the moment."
What confuses me especially is that I have a redirect page for purchase approval that IS working correctly in the onApprove function (seen below).
PayPal JavaScript SDK says this is the code to redirect customers to a customer URL:
paypal.Buttons({
onError: function (err) {
// For example, redirect to a specific error page
window.location.href = "/your-error-page-here";
}
}).render('#paypal-button-container');
This is what my onError function looks like:
onError: function (err) {
//My Redirect Page
window.location.href = "https://www.fitnessbydylan.com/error-page.html";
}
This is my full Javascript for my PayPal button.
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"1 MONTH DIGITAL COACHING","amount":{"currency_code":"USD","value":0.06,"breakdown":{"item_total":{"currency_code":"USD","value":0.06},"shipping":{"currency_code":"USD","value":0},"tax_total":{"currency_code":"USD","value":0.00}}}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Simulate a mouse click:
window.location.href = "http://www.fitnessbydylan.com/purchase-page.html";
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
},
onError: function (err) {
// My Redirect Page
window.location.href = "https://www.fitnessbydylan.com/error-page.html";
},
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
onError is only triggered when there is a technical problem with loading or using the buttons, which is a very rare situation. It is not triggered for card processing problems.

Can i get payments to my paypal account with help of paypal api

Is it possible to sell some non-physical product and get its payment directly into your personal paypal account? Has anyone did something like this?
It is certainly possible, and actually very easy. What kind of integration are you looking for? Maybe one of the buttons at http://www.paypal.com/buttons would be a good start for you.
Here is a sample of a VERY Simple checkout Script using REST API (Client Side Only Code)
First add this line to "head" of your HTML page:
{
<script src="https://www.paypal.com/sdk/js?client-
id=YOUR USER ID GOES HEREg&disable-funding=credit,card"></script>
}
Then add this to where you want your PayPal Button(s) to be on your HTML Page:
'<div style="width:30%" id="paypal-button-container"><p style="font-size:small">
<b>Checkout using your PayPal Acount <br>
or if you do not have a PayPal Account, you can pay with your Debit or Credit
Card (option at bottom of Pop-up Window).</b></p></div>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
onError: function (err) {
alert('An Error Occured, returning you to the Form. Please Check that you
are not submitting a Zero Amount and have Filled out the Form');
},
style: {
layout: 'horizontal',
color: 'gold',
shape: 'pill',
label: 'checkout',
size: 'responsive',
tagline: 'true',
},
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: 'GnG Order',
amount: {
value: cartTotal
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name +
'!');
});
if (details.error === 'INSTRUMENT_DECLINED') {
return actions.restart();
};
}
}).render('#paypal-button-container');
</script>'
That should do it for you. Be sure to login to the Developer Panel to set up your API credentials.

How to dynamically change currency & pass other data in PayPal Express Checkout

I want to accept payment in Multiple currencies & also autofill the Address/Name in PayPal form using Express Checkout method
I have tried going through various posts, paypal getting started, paypal community, but not able to find if it possible.
Currently, using Express Checkout I'm able to receive payment on changing the get parameter of the script.
<script src="https://www.paypal.com/sdk/js?client-id=valueOfClientID&currency=GBP"> </script>
Is is possible to pass the currency & name/address details in below code?
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '24'
}
}]
});
},
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',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');
</script>
Based on the currency dynamically inject the script to the page and pass the address object as mentioned in the link

Stuck with integration of Paypal Express Checkout ( Basic integration checkout.js version 4.0.0)

I'm trying to integrate Paypal Express Checkout into simple Shopping Cart. There are different ways to do that. Paypal recommends to choose between Basic or Advanced integration and version 4.0 of checkout.js (with REST API). So far so good.
I created Paypal App in my Paypal account to get credentials and start testing it.
The test was OK, but there are some misunderstandings here.
Checkout.js send the amount ( 1.00 ) and currency ( EUR ) to the Paypal servers via REST API (along with my credentials). And if the payment is finished OK - callback function onAuthorize is triggered and there are two parameters with response (data and actions). Well, here I call my own AJAX function to write transaction response data in my database. BUT... I get here only PaymentID and PayerID of the paid transaction?!! And if I want to search later into web interface of paypal.com - there is no such thing as PaymentID. There is only TransactionID ??? How to get other transaction details in the response in onAutorize callback function? How can I get TransactionID here to write down in my database? May be here I have to call Paypal API, or have to implement Paypal IPN (instant payment notification )? BUT how to call IPN API, if I don't have TransactionID :)
<div style="width: 906px; text-align: right; height: 100px;
margin-top: 50px;">
<div id="paypal-button"></div>
</div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
env: 'production', // Optional: specify 'sandbox' environment
style: {
size: 'medium',
shape: 'rect'
},
client: {
sandbox: 'xxx-my-credentials-xxx',
production: 'xxx-my-credentials-xxx'
},
payment: function() {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
amount: { total: '1.00', currency: 'EUR' }
}
]
});
},
commit: true, // Optional: show a 'Pay Now' button in the checkout flow
onAuthorize: function(data, actions) {
// Optional: display a confirmation page here
var EXECUTE_PAYMENT_URL = 'payment-process.php';
paypal.request.post(EXECUTE_PAYMENT_URL, { paymentID: data.paymentID, payerID: data.payerID, transactionID: data.transactionID, data: data }) .then(function(data) { }) .catch(function(err) { });
return actions.payment.execute().then(function() {
// Show a success page to the buyer
});
}
}, '#paypal-button');
</script>
To read the information from the transaction you need to call and save data JSON in database
return actions.payment.execute().then(function() {
actions.payment.get().then(function(data) {
if(data.state === 'approved'){
console.log(data);
var transactionId = data.id;
alert("Transaction ID: "+ transactionId + " \n State: " +data.state);
}else{
console.log(data);
}
});
});