创建条纹Webhook产品,向lambda发送POST请求时缺少图像和价格

问题描述 投票:0回答:1

我有一个成功的条纹webhook,它指向aws lambda函数,但是似乎我丢失了数据。我以为也许我不得不再次根据Stripe在Webhook中传递给我的lambda函数的产品ID,通过Strips 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
}

但是我的问题是如何获得产品价格和产品图片阵列?甚至Sku。我在这里想念的是什么。

提前感谢

node.js post aws-lambda stripe-payments
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.