0

我有一个成功的条带 webhook,它指向一个 aws lambda 函数,但似乎我缺少数据。我想也许我必须根据 stripe 在 webhook 中传递给我的 lambda 函数的产品 ID,通过 stripes api 第二次获取记录。但是,它们都具有相同的数据,具有正确名称属性的对象,在任何地方都看不到价格以及为空的图像数组。在 Stripe 中,产品既有价格又有图片。

这是我的 lambda 函数

// const axios = require('axios')
// const url = 'http://checkip.amazonaws.com/';
let response;
const SiteClient = require('datocms-client').SiteClient;
const client = new SiteClient('codegoeshere');

/**
 *
 * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
 * @param {Object} event - API Gateway Lambda Proxy Input Format
 *
 * Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html 
 * @param {Object} context
 *
 * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
 * @returns {Object} object - API Gateway Lambda Proxy Output Format
 * 
 */
exports.lambdaHandler = async (event, context, callback) => {
    console.log(event);
    client.items.create({
        title: JSON.parse(event.body).data.object.name,
        itemType: '223937'
      })
      .then((item) => {
        console.log(item);
      })
      .catch((error) => {
        console.error(error);
      });

    try {
        // const ret = await axios(url);
        response = {
            'statusCode': 200,
            'body': JSON.stringify({
                message: 'hello world',
                // location: ret.data.trim()
            })
        }
    } catch (err) {
        console.log(err);
        return err;
    }

    callback(null, response)
};

当条带 webhook 发送发布请求时,我的 aws 日志中的 console.log(event) 看起来像这样。我将不需要的数据替换为...

{
  resource: '/hello',
  path: '/hello/',
  httpMethod: 'POST',
  headers: {
    ...
  },
  multiValueHeaders: {
    ...
  },
  ...
    },
    ...
  },
  body: '{\n' +
    '  "id": "evt_1GbZb9Hk5l44uIELY8mE0xFl",\n' +
    '  "object": "event",\n' +
    '  "api_version": "2020-03-02",\n' +
    '  "created": 1587765735,\n' +
    '  "data": {\n' +
    '    "object": {\n' +
    '      "id": "prod_H9tNB6zuPJbDcI",\n' +
    '      "object": "product",\n' +
    '      "active": true,\n' +
    '      "attributes": [\n' +
    '        "name"\n' +
    '      ],\n' +
    '      "caption": null,\n' +
    '      "created": 1587765735,\n' +
    '      "deactivate_on": [\n' +
    '\n' +
    '      ],\n' +
    '      "description": null,\n' +
    '      "images": [\n' +
    '\n' +
    '      ],\n' +
    '      "livemode": false,\n' +
    '      "metadata": {\n' +
    '      },\n' +
    '      "name": "Red Hat From Mars",\n' +
    '      "package_dimensions": null,\n' +
    '      "shippable": true,\n' +
    '      "type": "good",\n' +
    '      "updated": 1587765735,\n' +
    '      "url": null\n' +
    '    }\n' +
    '  },\n' +
    '  "livemode": false,\n' +
    '  "pending_webhooks": 6,\n' +
    '  "request": {\n' +
    '    "id": "req_44TGYL9uyPZAkf",\n' +
    '    "idempotency_key": null\n' +
    '  },\n' +
    '  "type": "product.created"\n' +
    '}',
  isBase64Encoded: false
}

现在条纹 API 文档中有一个演示对象,看起来就像我得到的一样

{
  "id": "prod_H9s5JbTrI0tIcm",
  "object": "product",
  "active": true,
  "attributes": [
    "name"
  ],
  "caption": null,
  "created": 1587760882,
  "deactivate_on": [],
  "description": null,
  "images": [],
  "livemode": false,
  "metadata": {},
  "name": "lets see if this works",
  "package_dimensions": null,
  "shippable": true,
  "type": "good",
  "updated": 1587760883,
  "url": null
}

但是我的问题是如何获取 Product Price 和 Product Image 数组?甚至是Sku。我在这里想念什么。

提前谢谢

4

1 回答 1

0

我还需要在条纹仪表板的 webhook 中添加事件更新以创建条纹 sku。有点混乱,但现在我有了所有的数据。

于 2020-04-24T23:02:17.057 回答