Jump to content

Need help with JavaScript code

Hi P
Go to solution Solved by C2dan88,

Step 6.1 of link you posted shows how to send via post.

 

Replace /paypal-transaction-complete with the your paypal processing uri to on this line

return fetch('/paypal-transaction-complete', {

 

 

 

 

Original Paypal Implementation

 

Spoiler

<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',
          headers: {
            'content-type': 'application/json'
          },
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      });
    }
  
  }).render('#paypal-button-container');
</script>

 

 

Disclaimer: I don't know JavaScript at all :(

 

We are using Codeigniter (PHP) at work, handling the transactions through Paypal, everything is done and working.

 

However, I had been sending the info via GET for testing purposes, but now that everything is working it has to be done through POST.

 

Spoiler

<script>                                
	paypal.Buttons({
		createOrder: function(data, actions) {
                                                
		return actions.order.create({
			purchase_units: [{
				amount: {
				value: 'PLACEHOLDER'
				},
				description: 'PLACEHOLDER'
			}]
		});
		},

  		//		I just need to send: data.orderID, that's all		//
		onApprove: function(data, actions) {
			return actions.order.capture().then(function(details) {

				//		THIS IS SENDING IT THROUGH GET		//
				window.location="<?php echo base_url() ?>Paypal/index/"+data.orderID;
			});
		}

	}).render('#paypal-button-container');
</script>

 

 

What do I do to send it via POST? upon doing a quick google search I have found that it's not possible by using window.location

 

Thank you :)

 

Link to comment
Share on other sites

Link to post
Share on other sites

Not to be a dick, but since this is for a professional environment, wouldn't you want to pay for someone to take care of this? So you have some garantuees.
Playing with money even tho Paypal sets the door open wide for mis-use.
Just a friendly warning. :)
Goodluck finding a solution!

When i ask for more specs, don't expect me to know the answer!
I'm just helping YOU to help YOURSELF!
(The more info you give the easier it is for others to help you out!)

Not willing to capitulate to the ignorance of the masses!

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, HanZie82 said:

Not to be a dick, but since this is for a professional environment, wouldn't you want to pay for someone to take care of this? So you have some garantuees.
Playing with money even tho Paypal sets the door open wide for mis-use.
Just a friendly warning. :)
Goodluck finding a solution!

 

No worries, everything related to the processing is on a different code, already working :)

 

That code from my post is just the button, nothing else, all I have to do is send that data.orderID through post, but I don't know how :(

Link to comment
Share on other sites

Link to post
Share on other sites

Step 6.1 of link you posted shows how to send via post.

 

Replace /paypal-transaction-complete with the your paypal processing uri to on this line

return fetch('/paypal-transaction-complete', {

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, C2dan88 said:

Replace /paypal-transaction-complete with the your paypal processing uri to on this line


return fetch('/paypal-transaction-complete', {

 

Oh my god, now it worked! :D

 

I swear I had tried that before, chances are I entered an incorrect path

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×