我有一个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]);
阿晨1998
相关分类