具有服务器集成的 PayPal 客户端 JavaScript SDK - 设置付款金额

我正在尝试将客户端 PayPal JavaScript SDK 与 PayPal 服务器端 REST API 集成。我知道如何在客户端 JavaScript SDK 和服务器端 REST API 中创建新的 PayPal 订单。我已经成功地完成了这两件事。但问题是,无论我怎么做,都会有问题。如果我在服务器上创建新订单,但不在客户端代码中创建,则客户登录后显示的价格为 0.01 美分,而不是正确的价格,即使订单创建正确。

我可以同时使用客户端createOrder方法和服务器端订单创建,但我担心它将创建两个订单,甚至可能捕获两次付款。

我找不到集成服务器端订单创建并在用户登录后出现的 PayPal 对话框中设置价格的方法。

在不使用客户端方法的情况下,如何在用户登录后显示产品价格createOrder

如果我在服务器上创建订单并将订单 ID 传递回客户端代码,则客户端 JavaScript API 会出现 3 个有关 PATCH 的错误。我不明白。

我可以省略客户端createOrder方法,除了付款金额默认为 0.01 美分之外,一切正常。我不想那样。



绝地无双
浏览 65回答 2
2回答

尚方宝剑之说

这是我的解决方案,使用客户端 PayPal Javascript SDK 和服务器端 PayPal API 接受买家付款。该服务器代码特定于Apps Script,来自客户端的服务器调用也特定于Apps Script。注意:要“上线”,您必须:从网址中删除“沙箱”一词 - 请参阅:https ://developer.paypal.com/docs/paypal-plus/germany/integrate/test-and-go-live/#go-live使用不同的客户端和秘密凭据服务器代码 - Apps 脚本function payPalSettings_() {&nbsp; //see:&nbsp;&nbsp; //https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#createorder&nbsp; return {&nbsp; &nbsp; intent:'CAPTURE',//The PayPal JavaScript SDK defaults to capture if not set&nbsp;&nbsp; &nbsp; //but for purposes of explicitly making it clear what the code is doing -&nbsp; &nbsp; //it is being set here -&nbsp; &nbsp; //The Capture setting results in the capturing of funds immediately&nbsp;&nbsp; &nbsp; //after the buyer approves the purchase -&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; purchase_units:[&nbsp; &nbsp; &nbsp; {"custom_id":"abc123",//You can add a custom value to pass to PayPal&nbsp; &nbsp; &nbsp; &nbsp;"description":"Emails Director Gold",&nbsp; &nbsp; &nbsp; &nbsp;"amount":{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"currency_code":"USD",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"value":"2.95",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ],&nbsp; }}function getCredentials_() {&nbsp; var CLIENT_Live,Paypal_Client_Test,PayPalSecret_Test,rtrnObj,SECRET_Live;&nbsp;&nbsp;&nbsp; rtrnObj = {};&nbsp;&nbsp;&nbsp; Paypal_Client_Test = 'abc123';//You must get this from your PayPal account&nbsp; PayPalSecret_Test = '321cba';&nbsp;&nbsp;&nbsp; //For testing comment out the live credentials&nbsp; //CLIENT_Live = 'put it here';//You must get this from your PayPal account&nbsp; //SECRET_Live = 'put it here';&nbsp;&nbsp;&nbsp; rtrnObj.client = CLIENT_Live ? CLIENT_Live : Paypal_Client_Test;//If the live credential is available then use it&nbsp; rtrnObj.secret = SECRET_Live ? SECRET_Live : PayPalSecret_Test;&nbsp;&nbsp;&nbsp; return rtrnObj;}/* This code is for making calls to PayPal from the SERVER&nbsp;&nbsp; &nbsp;This server code must work together with the client side code&nbsp;*///To see the equivalent of this code go to://https://developer.paypal.com/docs/business/checkout/server-side-api-calls/create-order#1-add-server-code//which is the Add Server Code section and show the JavaScript codefunction captureThePayment(po) {try{&nbsp; var accessTkn,capture,options,PayPal_Capture_API,rCode;&nbsp; /*&nbsp; &nbsp; po.orderId - the order ID&nbsp; */&nbsp;&nbsp;&nbsp; /*&nbsp; &nbsp; See documentation at:&nbsp; &nbsp; https://developer.paypal.com/docs/checkout/reference/server-integration/capture-transaction/&nbsp;&nbsp;&nbsp; */&nbsp;&nbsp;&nbsp; //Logger.log('po 61',po)&nbsp;&nbsp;&nbsp; accessTkn = getAuthTkn_();&nbsp; PayPal_Capture_API = 'https://api.sandbox.paypal.com/v2/checkout/orders/' + po.orderId + '/capture';&nbsp; //Logger.log('PayPal_Capture_API',PayPal_Capture_API)&nbsp;&nbsp;&nbsp; options = {};&nbsp;&nbsp;&nbsp; options.muteHttpExceptions = true;&nbsp; options.method = 'post';&nbsp; options.headers = {&nbsp; &nbsp; //"Accept":"application/json",&nbsp; &nbsp; "Authorization": "Bearer " + accessTkn&nbsp; }&nbsp; options.contentType = 'application/json';//This needs to be used or it doesnt work&nbsp;&nbsp;&nbsp; capture = UrlFetchApp.fetch(PayPal_Capture_API,options);//Call PayPal to capture the order&nbsp; //Logger.log('capture.getResponseCode() 77',capture.getResponseCode())&nbsp; //Logger.log('capture 85',capture)&nbsp; //Logger.log('capture.error',capture.error)&nbsp; rCode = capture.getResponseCode();&nbsp;&nbsp;&nbsp; if (rCode !== 200 && rCode !== 201) {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; //Logger.log('capture.getContentText',capture.getContentText)&nbsp; &nbsp; throw new Error("Error capturing the payment: " + rCode);&nbsp; }&nbsp;&nbsp;&nbsp; //Logger.log('capture.getContentText',capture.getContentText)&nbsp;&nbsp;&nbsp; /*&nbsp; &nbsp; There is no response - just a response code&nbsp; &nbsp; To get order detail another request must be made to PayPal&nbsp; */&nbsp;&nbsp;&nbsp; // Do your own custom processing&nbsp; return true;//The capture option doesnt return anything but a response code - it doesnt return order details -&nbsp; //to get order details you would need to use the base API url with just the order number on the end-&nbsp; //See https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/}catch(e){&nbsp; //Logger.log('message',e.message)&nbsp; //Logger.log('stack',e.stack)}}function createA_PayPalOrder() {try{&nbsp; var authTkn,options,order,paySets,payload,response;&nbsp; authTkn = getAuthTkn_();&nbsp; //2 Set up your server to receive a call from the client&nbsp;&nbsp; PAYPAL_ORDER_API = 'https://api.sandbox.paypal.com/v2/checkout/orders/';//Must be changed for live mode&nbsp;&nbsp;&nbsp; // 3 Call PayPal to set up a transaction&nbsp; options = {};&nbsp;&nbsp;&nbsp; paySets = payPalSettings_();&nbsp; //console.log('paySets 121' + paySets)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.muteHttpExceptions = true;//&nbsp; options.method = 'post';&nbsp; options.headers = {&nbsp; &nbsp; "Accept":"application/json",&nbsp; &nbsp; "Authorization": "Bearer " + authTkn&nbsp; }&nbsp; options.contentType = 'application/json';&nbsp; options.payload = JSON.stringify(paySets);&nbsp;&nbsp;&nbsp; response = UrlFetchApp.fetch(PAYPAL_ORDER_API,options);//Call PayPal to set up a transaction&nbsp; //console.log('response.getResponseCode() 131' + response.getResponseCode())&nbsp;&nbsp;&nbsp; /*&nbsp; &nbsp; The response returned should look like:&nbsp; &nbsp; {"id":"abc123",&nbsp; &nbsp; "status":"CREATED",&nbsp; &nbsp; "links":[{"href":"https://api.sandbox.paypal.com/v2/checkout/orders/abc123",&nbsp; &nbsp; "rel":"self",&nbsp; &nbsp; "method":"GET"},&nbsp; &nbsp; {"href":"https://www.sandbox.paypal.com/checkoutnow?token=abc123",&nbsp; &nbsp; "rel":"approve",&nbsp; &nbsp; "method":"GET"},&nbsp; &nbsp; {"href":"https://api.sandbox.paypal.com/v2/checkout/orders/abc123",&nbsp; &nbsp; "rel":"update","method":"PATCH"},&nbsp; &nbsp; {"href":"https://api.sandbox.paypal.com/v2/checkout/orders/abc123/capture",&nbsp; &nbsp; "rel":"capture",&nbsp; &nbsp; "method":"POST"}]}&nbsp;&nbsp;&nbsp; */&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //4 Handle any errors from the call&nbsp; if (response.getResponseCode() !== 201) {&nbsp; &nbsp; //console.log('response.getContentText() 135' + response.getContentText())&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; //console.log(response);&nbsp; &nbsp; return "error";&nbsp; }&nbsp; order = response.getContentText();&nbsp; //order = JSON.parse(order);&nbsp;&nbsp;&nbsp; //console.log('order.id 166' + order.id)&nbsp; //5 Return a successful response to the client&nbsp; return order;}catch(e){&nbsp; //console.log('message' + e.message)&nbsp; //console.log('stack' + e.stack)}}function getAuthTkn_() {try{&nbsp; var auth,basicAuth,cacheService,creds,credentialClient,credentialSecret,keyConcat,options,payPalToken,PAYPAL_OAUTH_API,paySets,&nbsp; &nbsp; &nbsp; payload,response,tkn;&nbsp; /*Log into your developer dashboard: https://www.paypal.com/signin?returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications&nbsp; &nbsp; Note that the sandbox (for testing) and the live modes both have their own apps - So I would create different app names for&nbsp; &nbsp; each one -&nbsp; &nbsp; If you have not created an app then create an app&nbsp; &nbsp; If you need to create an app then you will need to generate the credentials&nbsp; &nbsp; If you already have an app and credentials then you can use those&nbsp; &nbsp; When getting your credentials the first thing you must do is choose either sandbox or live -&nbsp; */&nbsp;&nbsp;&nbsp; cacheService = CacheService.getDocumentCache();&nbsp;&nbsp;&nbsp; try{&nbsp; &nbsp; payPalToken = cacheService.get("authTkn");&nbsp; }catch(e){&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; if (payPalToken) {//There is already a PayPal auth token generated and in Cache&nbsp; &nbsp; return payPalToken;&nbsp; }&nbsp;&nbsp;&nbsp; creds = getCredentials_();&nbsp;&nbsp;&nbsp; credentialClient = creds.client;&nbsp; credentialSecret = creds.secret;&nbsp;&nbsp;&nbsp; PAYPAL_OAUTH_API = 'https://api.sandbox.paypal.com/v1/oauth2/token/';//1B Use the PayPal APIs which are called with the following URLs -&nbsp; keyConcat = credentialClient + ':' + credentialSecret;//concatenate the client and secret credentials&nbsp;&nbsp;&nbsp; basicAuth = Utilities.base64Encode(keyConcat);//Base 64 encode&nbsp;&nbsp;&nbsp; options = {};&nbsp; payload = {};&nbsp; payload.grant_type = "client_credentials";&nbsp;&nbsp;&nbsp; options.muteHttpExceptions = true;//&nbsp; options.method = 'post';&nbsp; options.headers = {&nbsp; &nbsp; "Accept":"application/json",&nbsp; &nbsp; "Authorization": "Basic " + basicAuth&nbsp; }&nbsp; options.payload = payload;&nbsp;&nbsp;&nbsp; response = UrlFetchApp.fetch(PAYPAL_OAUTH_API, options);//1C Get an access token from the PayPal API&nbsp; //Logger.log('response.getResponseCode() 80',response.getResponseCode())&nbsp;&nbsp;&nbsp; auth = response.getContentText();&nbsp; //Logger.log('auth 83',auth)&nbsp;&nbsp;&nbsp; /*&nbsp; &nbsp; The response returned should look like this:&nbsp; &nbsp; {"scope":"https://uri.paypal.com/services/invoicing&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/disputes/read-buyer&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/payments/realtimepayment&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/disputes/update-seller&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/payments/payment/authcapture openid&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/disputes/read-seller&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/payments/refund&nbsp;&nbsp; &nbsp; &nbsp; https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.*&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/subscriptions&nbsp;&nbsp; &nbsp; &nbsp; https://uri.paypal.com/services/applications/webhooks",&nbsp; &nbsp; &nbsp; "access_token":"abc123",&nbsp; &nbsp; &nbsp; "token_type":"Bearer",&nbsp; &nbsp; &nbsp; "app_id":"APP-abc123",&nbsp; &nbsp; &nbsp; "expires_in":32400,&nbsp; &nbsp; &nbsp; "nonce":"2020-12-09T01:07:abc123"}&nbsp; */&nbsp;&nbsp;&nbsp; if (!auth) {&nbsp; &nbsp; throw new Error("Authorization information not retrieved from PayPal");&nbsp; }&nbsp; auth = JSON.parse(auth);&nbsp; //Logger.log('auth',auth)&nbsp; //Logger.log('auth.access_token 90',auth.access_token)&nbsp;&nbsp;&nbsp; tkn&nbsp; = auth.access_token;&nbsp; cacheService.put("authTkn", tkn, 180);//Save in cache for 3 minutes&nbsp; return tkn;}catch(e){&nbsp; Logger.log('message',e.message)&nbsp; Logger.log('stack',e.stack)&nbsp; console.log(e)}}客户端 HTML<!-- This code uses the client side JavaScript PayPal SDK --><div style="text-align: center;">&nbsp; <div id="paypal-button-container"></div></div>客户端 JavaScript<!--&nbsp; Required files:&nbsp; This code works together with the server code -&nbsp;&nbsp;&nbsp;&nbsp; This PayPal payment system uses both the PayPal javascript SDK AND server side PayPal API calls -&nbsp;&nbsp;&nbsp; This PayPal payment system uses Smart Payment Buttons - See: https://developer.paypal.com/docs/checkout/&nbsp;&nbsp;&nbsp; The two most important documentation links are:&nbsp; https://developer.paypal.com/docs/checkout/integrate/&nbsp; https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/&nbsp;&nbsp;&nbsp; For configuration settings there is information at:&nbsp; https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/&nbsp;&nbsp;&nbsp; Note that this PayPal implementation does NOT require there to be a button definition in your PayPal settings -&nbsp;&nbsp;&nbsp; The PayPal JavaScript client side SDK is newer than the checkout.js&nbsp; See this Link: https://developer.paypal.com/docs/archive/checkout/how-to/server-integration/&nbsp; For an overview of the PayPal checkout with server integration -&nbsp; It is very important to understand the "sandbox" and the "production" settings -&nbsp; There are mutliple settings that must all be for either "sandbox" or "production"&nbsp; If you mix "sandbox" and "production" credentials and API links then your code will not work&nbsp; and the error messages may not help you to understand what the real problem is -&nbsp;&nbsp;&nbsp; Anything to do with "sandbox" is for testing purposes -&nbsp; "production" is for accepting live payments from customers -&nbsp;&nbsp;&nbsp; The terminology that PayPal uses for the credentials is:&nbsp; client id - The client side credential key&nbsp; secret - The server side credential key&nbsp;&nbsp;&nbsp; Credentials need to be in three different settings-&nbsp; 1 - Client side script tag - client id&nbsp; 2 - Server side variable - client id&nbsp; 3 - Server side variable - secret&nbsp;&nbsp;&nbsp; To test your PayPal code you must do multiple things:&nbsp; 1 - Create sandbox (test) client and secret credentials&nbsp; 2 - use a special buyer PayPal account:&nbsp; &nbsp; &nbsp; https://developer.paypal.com/docs/checkout/integrate/--><script src="https://www.paypal.com/sdk/js?client-id= YOUR CLIENT ID HERE - MAKE SURE IT MATCHES EITHER SANDBOX OR PRODUCTION &currency=USD"></script><script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;window.payPalPaymentComplete = function(orderId) {&nbsp; showModalMessageBox("Payment is complete","COMPLETE!");&nbsp;&nbsp;}window.backToStartPay = function() {&nbsp; //Return to the dialog to buy something&nbsp;&nbsp;}function capture_the_order(po) {&nbsp; //Use the google.script.run API to call the server&nbsp; //This is specific to Google Apps Script&nbsp; return new Promise (function (resolve,reject) {&nbsp; &nbsp; google.script.run&nbsp; &nbsp; &nbsp; .withSuccessHandler (function (result) {&nbsp; &nbsp; &nbsp; &nbsp; //cl('result 62' + result)&nbsp; &nbsp; &nbsp; &nbsp; resolve (result);//What resolve does is return the result from the server back to the FIRST anonymous function in the "then" part&nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; .withFailureHandler (function (error) {&nbsp; &nbsp; &nbsp; &nbsp; //cl('error 66' + error)&nbsp; &nbsp; &nbsp; &nbsp; reject (error);&nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; .captureThePayment(po);//Call the server to create a PayPal order&nbsp; &nbsp; })}function iWillWaitForU() {&nbsp; //Use the google.script.run API to call the server&nbsp; //This is specific to Google Apps Script&nbsp; return new Promise (function (resolve,reject) {&nbsp; &nbsp; google.script.run&nbsp; &nbsp; &nbsp; .withSuccessHandler (function (result) {&nbsp; &nbsp; &nbsp; &nbsp; //cl('result 62' + result)&nbsp; &nbsp; &nbsp; &nbsp; resolve (result);//What resolve does is return the result from the server back to the FIRST anonymous function in the "then" part&nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; .withFailureHandler (function (error) {&nbsp; &nbsp; &nbsp; &nbsp; //cl('error 66' + error)&nbsp; &nbsp; &nbsp; &nbsp; reject (error);&nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; .createA_PayPalOrder();//Call the server to create a PayPal order&nbsp; &nbsp; })}function initPayPalButton() {&nbsp; /*&nbsp; &nbsp; This is a server side integration of the client side PayPal JavaScript SDK -&nbsp; &nbsp; The createOrder method makes a call to the PayPal API -&nbsp; &nbsp; The PayPal documentation uses the fetch() method but Apps Script uses google.script.run&nbsp; &nbsp; to make a server call so the PayPal example must be modified -&nbsp; */&nbsp; paypal.Buttons({&nbsp; &nbsp; style: {&nbsp; &nbsp; &nbsp; shape: 'rect',&nbsp; &nbsp; &nbsp; color: 'gold',&nbsp; &nbsp; &nbsp; layout: 'vertical',&nbsp; &nbsp; &nbsp; label: 'paypal',&nbsp; &nbsp; },&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; createOrder : function() {&nbsp; &nbsp; &nbsp; //console.log('createOrder 93' + 'order')&nbsp; &nbsp; &nbsp; return iWillWaitForU()// Call the server code to complete the payment transaction&nbsp; &nbsp; &nbsp; &nbsp; //This both creates and executes the transaction&nbsp; &nbsp; &nbsp; &nbsp; .then(function(response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log('response 89' + response)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return JSON.parse(response);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //window.PayPalOrderId = orderInfo.id;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //return orderInfo.id;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },//THERE MUST BE A COMMA HERE!!!!&nbsp; This is a list of functions seperated by a comma&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function (error) {//Because this is the second function this is what gets called for an error&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showModalMessageBox("There was an error in the PayPal button!","ERROR!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log(error);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "Error";&nbsp; &nbsp; &nbsp; &nbsp; }).then(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function(orderObj){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//console.log('orderObj.orderID' + orderObj.id)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return orderObj.id;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; },&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; onApprove: function() {&nbsp; &nbsp; &nbsp; //console.log('onapprove ran')&nbsp; &nbsp; &nbsp; startSpinner();&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; backToStartPay();&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; capture_the_order({"which":"capture","orderId":window.PayPalOrderId})&nbsp; &nbsp; &nbsp; &nbsp; .then(&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; function(hadSuccess) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //cl('hadSuccess 89',hadSuccess)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (hadSuccess) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; payPalPaymentComplete();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log('Transaction completed !');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showModalMessageBox("There was an error getting the payment!","ERROR!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log(error);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopSpinner();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },//THERE MUST BE A COMMA HERE!!!!&nbsp; This is a list of functions seperated by a comma&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function (error) {//Because this is the second function this is what gets called for an error&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showModalMessageBox("There was an error getting the payment!","ERROR!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log(error);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopSpinner();&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; },&nbsp; &nbsp; onCancel: function (data, actions) {&nbsp; &nbsp; &nbsp; // Show a cancel page or return to cart&nbsp; &nbsp; &nbsp; showModalMessageBox('PayPal Session was cancelled',"CANCELLED!");&nbsp; &nbsp; &nbsp; backToStartPay();&nbsp; &nbsp; },&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; onError: function(err) {&nbsp; &nbsp; &nbsp; showModalMessageBox("There was an error in the PayPal button!","ERROR!");&nbsp; &nbsp; &nbsp; //console.log(err);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; }).render('#paypal-button-container');//Render the PayPal button into the html element with id #paypal-button-container -&nbsp;&nbsp; //See HTML file - H_PayPal_New&nbsp;&nbsp;}initPayPalButton();</script>

catspeake

如果我在服务器上创建订单并将订单 ID 传递回客户端代码,则客户端 JavaScript API 会出现 3 个有关 PATCH 的错误。我不明白。您需要提供有关此问题的更多详细信息,因为您似乎需要帮助。此示例显示了调用服务器的正确方法:https ://developer.paypal.com/demo/checkout/#/pattern/server必须完全避免使用actions.order.create()and 。.capture()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript