2016-09-27 91 views
0

此独立的Google脚本Web服务始终从PayPal(resp = INVALID)返回INVALID。 PayPal IPN模拟器显示握手成功的消息。PayPal IPN在带有Google脚本的沙盒中返回INVALID

我错过了什么?

function doPost(e) { 

    var isProduction = false; 

    //if(typeof e == 'undefined') 
    //return ContentService.createTextOutput(JSON.stringify(e.parameter)); 

    var strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr" 
    var strLive = "https://www.paypal.com/cgi-bin/webscr" 
    var paypalURL = strSandbox 

    if (isProduction) paypalURL = strLive; 
    var payload = "cmd=_notify-validate&" + e.postData.contents; 


    var options = 
    { 
     "method" : "post", 
     "payload" : payload 
    }; 

    var resp = UrlFetchApp.fetch(paypalURL, options); 
} 
+0

http://stackoverflow.com/questions/1485832/paypal-sandbox-ipn-return-invalid你有没有检查过这个? – Deep

回答

1

让一切工作后,我在这里提供我的工作实施骨架:

function doPost(e) { 

    var isProduction = false; 

    //if(typeof e == 'undefined') 
    //return ContentService.createTextOutput(JSON.stringify(e.parameter)); 

    var strSimulator = "https://www.sandbox.paypal.com/cgi-bin/webscr" 
    var strLive = "https://www.paypal.com/cgi-bin/webscr" 
    var paypalURL = strSimulator 

    if (isProduction) paypalURL = strLive; 
    var payload = "cmd=_notify-validate&" + e.postData.contents; 
    payload = payload.replace("+", "%2B"); 

    var options = 
    { 
     "method" : "post", 
     "payload" : payload, 
    }; 

    var resp = UrlFetchApp.fetch(paypalURL, options); //Handshake with PayPal - send acknowledgement and get VERIFIED or INVALID response 

    if (resp == 'VERIFIED') { 
    if (e.parameter.payment_status == 'Completed') { 
     if (e.parameter.receiver_email == '[email protected]') { 
     //Convert to reference currency (USD) if paid in any other currency 
     var exchangeRate = 1; 
     if ((e.parameter.exchange_rate)) { 
      exchangeRate = parseFloat(e.parameter.exchange_rate); 
     } 
     var paidUSD = isPaymentValid(parseFloat(e.parameter.mc_gross), e.parameter.mc_currency, exchangeRate); //Convert paid amound to reference currency (USD) 
     if (paidUSD == 0.0) { 
      //My function returns 0.0 if product cost not found in my DB. I raise some notification here to check it out 
      return false; 
     } 
     if (paidUSD > 0.0) { 
      //All validated - can process the payment 
      var processSuccess = processDownloadRequest(e); 

      if (!(processSuccess)) { 
      //Process of payment failed - raise notification to check it out 
      } 
     } else { 
      //Payment does not equal expected purchase value 
     } 
     } else { 
     //Request did not originate from my PayPal account 
     } 
    } else { 
    //Payment status not Completed 
    } 
    } else 
    { 
    //PayPal response INVALID 
    } 
}