How to access javascript object?

Hi,

I am tyring to add PayPal Express Checkout into my website, all is working fine, but I am not able to get the transaction ID using data[“id”] and it keeps on saying undefined.

How do I access the object ? If i just alert(data) it says object object. How do I see what objects are there in the data ?

Below is my code:

<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
	</head>
	
	<body>
		<div id="paypal-button"></div>
		
		<script src="https://www.paypalobjects.com/api/checkout.js"></script>
		<script>
			paypal.Button.render({
				// Configure environment
				env: 'sandbox',
				client: {
					sandbox: 'demo_sandbox_client_id',
					production: 'demo_production_client_id'
				},
				// Customize button (optional)
				locale: 'en_US',
				style: {
					size: 'small',
					color: 'gold',
					shape: 'pill',
				},
				// Set up a payment
				payment: function(data, actions) {
					return actions.payment.create({
						transactions: [{
							amount: {
								total: '0.01',
								currency: 'USD'
							}
						}]
					});
				},
				// Execute the payment
				onAuthorize: function(data, actions) {
					return actions.payment.execute().then(function() {
						var resultDOM = JSON.stringify(data, null, 2);
						var payID = data['id'];
						alert(payID);

						// Show a confirmation message to the buyer
						window.alert('Thank you for your purchase and ID is: ' + payID);
					});
				}
			}, '#paypal-button');
		</script>
		
		<script src="https://code.jquery.com/jquery.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>

Please help.

Thanks.

console.log(data)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.