Extra variabile in payments

PiotrM
Contributor
Contributor

I try to integrate my page with paypal, and I decide to use Client Side REST, theoretical all is correct but i need add some extra variables like order number or payment description, I want ask if it's possible to do this and haw and if its possible to get back full name of country not only country code document.querySelector('#country').innerText = shipping.country_code; 

My full 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>
</head>

<body>


<div id="paypal-button-container"></div>

<div id="confirm" class="hidden">
<div>Ship to:</div>
<div><span id="recipient"></span>, <span id="line1"></span>, <span id="city"></span></div>
<div><span id="state"></span>, <span id="zip"></span>, <span id="country"></span></div>

<button id="confirmButton">Complete Payment</button>
</div>

<div id="thanks" class="hidden">
Thanks, <span id="thanksname"></span>!
</div> <script> paypal.Button.render({ env: 'sandbox', // sandbox | production client: { sandbox: 'some id', production: '' }, payment: function(data, actions) { return actions.payment.create({ payment: { transactions: [ { amount: { total: '0.01', currency: 'USD' } } ] } }); }, // Wait for the payment to be authorized by the customer onAuthorize: function(data, actions) {

// Get the payment details

return actions.payment.get().then(function(data) {

// Display the payment details and a confirmation button

var shipping = data.payer.payer_info.shipping_address;

document.querySelector('#recipient').innerText = shipping.recipient_name;
document.querySelector('#line1').innerText = shipping.line1;
document.querySelector('#city').innerText = shipping.city;
document.querySelector('#state').innerText = shipping.state;
document.querySelector('#zip').innerText = shipping.postal_code;
document.querySelector('#country').innerText = shipping.country_code;

document.querySelector('#paypal-button-container').style.display = 'none';
document.querySelector('#confirm').style.display = 'block';

// Listen for click on confirm button

document.querySelector('#confirmButton').addEventListener('click', function() {

// Disable the button and show a loading message

document.querySelector('#confirm').innerText = 'Loading...';
document.querySelector('#confirm').disabled = true;

// Execute the payment

return actions.payment.execute().then(function() {

// Show a thank-you note

document.querySelector('#thanksname').innerText = shipping.recipient_name;

document.querySelector('#confirm').style.display = 'none';
document.querySelector('#thanks').style.display = 'block';
});
});
});
}

}, '#paypal-button-container'); </script> </body>

 

 

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS_Andre
Moderator
Moderator

Hi, you can pass the transaction variables you find in this link and they will be recorded in your transaction. Then you can retrieve these variables through the IPN notification.
For example passing these variables in your payment creation will be returned in your IPN notification where you will also get the country full name in the variable "address_country":

payment: function(data, actions) {

                return actions.payment.create({
                    payment: {
                        transactions: [
                            {
                                amount: { total: '0.01', currency: 'USD' },
                                description: 'My transaction description',
                                custom: 'My order number is PORD-23499392',
                            }
                        ]
                    }
                });
            },

View solution in original post

Login to Me Too
2 REPLIES 2
Solved

MTS_Andre
Moderator
Moderator

Hi, you can pass the transaction variables you find in this link and they will be recorded in your transaction. Then you can retrieve these variables through the IPN notification.
For example passing these variables in your payment creation will be returned in your IPN notification where you will also get the country full name in the variable "address_country":

payment: function(data, actions) {

                return actions.payment.create({
                    payment: {
                        transactions: [
                            {
                                amount: { total: '0.01', currency: 'USD' },
                                description: 'My transaction description',
                                custom: 'My order number is PORD-23499392',
                            }
                        ]
                    }
                });
            },

Login to Me Too

PiotrM
Contributor
Contributor

That's what I need. Thanks

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.