Paypal and session variables - paypal

Hi This is all out of my league so I could do with some help with this.
I have a simple website that uses paypal as the means of payment, but all payment will be different. With the below code if I have a fixed number it works fine but as mentioned it will be a different amount each time. I am using classic asp and the session to help with the variable but it's not working.
In my ASP page I have a simple test code:
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
Session("pay") = "1.00"
<div id="paypal-button-container" style="float: right;" style="width: 50%"></div>
and in the JS file
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '<%=Session("pay")%>', currency: 'GBP' }
}
]
},

Related

PayPal Smart Payments: changing the currency code

I'm trying to set up PayPal Smart Payments on a webpage. I'm using the example they give on here: https://developer.paypal.com/docs/checkout/integrate/
If I have currency_code set to USD it works fine, but if I change it to anything else, such as CAD or GBP the window won't load. What am I doing wrong?
<script src="https://www.paypal.com/sdk/js?client-id=sb"></script>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
'purchase_units': [{
'amount': {
'currency_code': 'USD',
'value': '5',
},
}]
})
}
}).render('body')
</script>
For some reason this example won't run here on Stack Overflow, but it runs fine on JSFiddle, so I have made two examples with the currency_code set differently.
'currency_code': 'USD': https://jsfiddle.net/liquidmetalrob/8y3p52fh/
'currency_code': 'GBP': https://jsfiddle.net/liquidmetalrob/8y3p52fh/1
The first example will load the PayPal window, and you need a PayPal Sandbox account to log into it. So if you want to log in you can use the throwaway account that I just created. Username: sb-ilukn1050819#personal.example.com password: pRKCu9.> But the important question is why does the window not even load in the second example?
I found the answer here: https://developer.paypal.com/docs/checkout/reference/customize-sdk/
You have to add the currency code to the script URL instead, and remove it from the JS.
<script
src="https://www.paypal.com/sdk/js?client-id=sb&currency=GBP">
</script>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
'purchase_units': [{
'amount': {
'value': '5',
},
}]
})
}
}).render('body')
</script>
Note: The client-id can be set to sb for testing, but in production you use your own one.

PayPal Express Checkout Shipping Calculations

I would like to:
Have the user log into paypal
Fetch the users information (billing&shipping addresses)
Then calculate the shipping fee
Place the payment
But, how can I receive the address and calculate the fee before I place the payment?
<script>
paypal.Button.render({
// Configure environment
env: '<?php echo $paypal->paypalEnv; ?>',
client: {
sandbox: '<?php echo $paypal->paypalClientID; ?>',
production: '<?php echo $paypal->paypalClientID; ?>'
},
// Customize button (optional)
locale: 'de_DE',
style: {
size: 'small',
color: 'gold',
shape: 'rect',
},
// Set up a payment
payment: function (data, actions) {
return actions.payment.create({
transactions: [{
amount: {
total: '10',
currency: 'EUR'
}
}]
});
},
// Execute the payment
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.location = "process.php?paymentID="+data.paymentID+"&token="+data.paymentToken+"&payerID="+data.payerID+"&pid=<?php echo $productID; ?>";
});
}
}, '#paypal-button');
</script>
Instead of "return actions.payment.execute()" calling the execute directly, I would like to fetch the address, then show the final basket with all the costs and then click on "pay now" - how can I do this?
Your sample is an older version of PayPal's checkout.js
Start by switching to the latest version of the PayPal Checkout: https://developer.paypal.com/docs/checkout/
Demo of client-side pattern: https://developer.paypal.com/demo/checkout/#/pattern/client
In the onApprove function, you can use the data object to get the address and do Javascript calculations about adding shipping before the capture() call with a modified total.
If you want to do the calculations on your server rather than in Javascript (more secure/reliable), use a server-side pattern:
https://developer.paypal.com/demo/checkout/#/pattern/server
thank you! mhhh okay but what has to be in the serverside part? i dont see any example of the actions to receive the buyers adress information before checkout and afterwards. ?
/demo/checkout/api/paypal/order/create

How can i find Braintree Sandbox Auth Key

I am working with braintree paypal checkout function, i found jquery code for that, i need to place Braintree Sandbox Auth Key in jquery variable, i created account in braintree, i tried all that code, but in jquery console log it says authrization failed, can anyone please help me where can i find that code ?
Here is my sameple code
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script src="https://js.braintreegateway.com/web/3.11.0/js/client.min.js"></script>
<script src="https://js.braintreegateway.com/web/3.11.0/js/paypal-checkout.min.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
var BRAINTREE_SANDBOX_AUTH = '38mqtdwp4nth5tbk';
// Render the PayPal button
paypal.Button.render({
// Pass in the Braintree SDK
braintree: braintree,
// Pass in your Braintree authorization key
client: {
sandbox: BRAINTREE_SANDBOX_AUTH,
production: '<insert production auth key>'
},
// Set your environment
env: 'sandbox', // sandbox | production
// Wait for the PayPal button to be clicked
payment: function(data, actions) {
// Make a call to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1', currency: 'USD' }
}
]
}
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Call your server with data.nonce to finalize the payment
console.log('Braintree nonce:', data.nonce);
// Get the payment and buyer details
return actions.payment.get().then(function(payment) {
console.log('Payment details:', payment);
});
}
}, '#paypal-button-container');
</script>
</body>
I need to place code in this variable var BRAINTREE_SANDBOX_AUTH = '38mqtdwp4nth5tbk'; can anyone help me to resolve this issue ?
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support#braintreepayments.com.
It looks like you are setting your BRAINTREE_SANDBOX_AUTH variable to a Merchant ID, rather than a Client Token. In order to initiate the Braintree checkout, you will need to generate, then pass in a client_token.
You generate the client_token on your server, then pass it into your client-side call: braintree.client.create().
If successful, braintree.client.create() will return a client instance that you can use to create a PayPal checkout component with braintree.paypalCheckout.create().
Within the paypalCheckout component, you can configure your PayPal button using paypal.Button.render().

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);
}
});
});

paypal Javascript Integration - What's form Action Parameter?

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