亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從其API檢索條紋發票時,如何擴展對象以檢索信用卡詳細信息和其他信息?

從其API檢索條紋發票時,如何擴展對象以檢索信用卡詳細信息和其他信息?

飲歌長嘯 2021-04-27 21:18:14
我有一個Google Apps腳本,可以訪問Stripe API,并從Stripe發票參考中檢索數據,并將數據添加到Google表格中。Stripe提到我可以擴展對象以獲得擴展對象引用的更多信息。但是我對使用API還是很陌生,所以我不確定該怎么做。我認為卡住的原因是因為我是從URL(即https://api.stripe.com/v1/invoices/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx)中提取發票數據。我不確定如何修改URL來擴展對象(或者在下面的代碼中應該在哪里執行)。例如,我要擴展“收費”對象以包括有關付款的更多詳細信息。我想從收費對象中獲取的數據將是卡類型(例如:Visa),有效期,最后四位數字。我可能會對Customer對象做同樣的事情,以訪問有關發票的客戶詳細信息。這是我目前正在使用的Google Apps腳本:function onOpen() {  var ui = SpreadsheetApp.getUi();  ui.createMenu('Stripe')    .addItem('Retrieve Invoice Data','getInvoiceObj')    .addToUi();}function getInvoiceObj()   {    var apiKey, content, options, response, secret, url;    //API Key    secret = "rk_live_xxxxxxxxxxxxxxxxxxxxxxxxxx";    apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";    //Stripe API invoice URL     url = "https://api.stripe.com/v1/invoices/xxxxxxxxxxxxxxxxxxxxxxxxxx";    options = {      "method" : "GET",      "headers": {        "Authorization": "Bearer " + secret       },      "muteHttpExceptions":true    };    response = UrlFetchApp.fetch(url, options);    //Push data to Sheet from invoice. **Writes over existing Sheet data**    content = JSON.parse(response.getContentText());    var sheet = SpreadsheetApp.getActiveSheet();    //Retrieves currency type and adds to Sheet    sheet.getRange(5,2).setValue([content.currency.toUpperCase()]);    //Invoice amount due    sheet.getRange(3,2).setValue([content.amount_due]);    //Invoice date    sheet.getRange(1,2).setValue([content.date]);    //Invoice period begin    sheet.getRange(6,2).setValue([content.lines.data[0].period.start]);    //Invoice period end    sheet.getRange(7,2).setValue([content.lines.data[0].period.end]);    //Number of licenses    sheet.getRange(10,2).setValue([content.lines.data[0].quantity]);    //Invoice number    sheet.getRange(13,2).setValue([content.number]);
查看完整描述

1 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

您在這里有兩個選擇:

  1. 提取發票時,Stripe API返回一個發票對象1,該對象又具有一個charge包含費用ID的字段。然后,您可以單獨致電v1/charges/{charge_id_goes_here}以獲取費用明細。

  2. charge提取發票時,展開。我不熟悉UrlFetchApp,但是您必須在請求中指定要擴展的charge對象。您將發送一個GET請求,其中包含您想擴展為的對象application/x-www-form-urlencoded。看看如何在cURL中完成操作,這可能對您有幫助:https ://stripe.com/docs/api/expanding_objects?lang =curl

另外,如果可以的話,我建議您使用官方的stripe-node庫,這將使與Stripe API的交互更加容易


查看完整回答
反對 回復 2021-05-13
  • 1 回答
  • 0 關注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號