Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

asp.net mvc - How can I display javascript object for paypal api?

I would like to display the details of the payment after users have make a purchase using paypal api. I realised the data is stored in console.log(details) How do I view the console.log(details) in another html page and insert it in the payment database? Here is my codes for the paypal api:

<head>
<meta charset="utf-8">
<title>My Orders</title>
<link rel=" stylesheet" href="~/styles/StyleSheet2.css">
<script src="https://www.paypal.com/sdk/js?client-id=AchXBKgrx7hxmn4m87StLCAuDD76_D4vX0vMqV2XAEyhhiHmO5bwB7O6uyZ3bW8KiyjVdnJdgW0aCh8e"></script>
<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) {
               console.log(details)
               window.location.replace("http://localhost:62941/Product/Success")
           });
       },

       onCancel: function (data) {
           
           window.location.replace("http://localhost:62941/Product/Unsuccessfulpayment")

       }

    
    }).render('#paypal-button-container');



    
</script>
question from:https://stackoverflow.com/questions/65858728/how-can-i-display-javascript-object-for-paypal-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How do I view the console.log(details) in another html page and insert it in the payment database?

Don't. Do not use actions.order.capture() on the client side and then store information in a database.

If you want to store information in a database, do the capture on a server.

Here is the approval flow to use: https://developer.paypal.com/demo/checkout/#/pattern/server

Pair this with two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...