我有一個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]);
從其API檢索條紋發票時,如何擴展對象以檢索信用卡詳細信息和其他信息?
飲歌長嘯
2021-04-27 21:18:14