Skip to content

Instantly share code, notes, and snippets.

@joshuaaguilar20
Created September 27, 2019 18:21
Show Gist options
  • Save joshuaaguilar20/9cfd36c60c10f8057dc20f9eee2c926a to your computer and use it in GitHub Desktop.
Save joshuaaguilar20/9cfd36c60c10f8057dc20f9eee2c926a to your computer and use it in GitHub Desktop.
API returning different Data
{
"id": "sku_FI4lrgGXvza0nv",
"object": "sku",
"active": true,
"attributes": {
"name": "LC-81"
},
"created": 1561053825,
"currency": "usd",
"image": "https://files.stripe.com/links/fl_live_WSngUWJBUIaD4RyvoKBsv9gL",
"inventory": {
"quantity": null,
"type": "infinite",
"value": null
},
"livemode": true,
"metadata": {},
"package_dimensions": null,
"price": 3800,
"product": "prod_FI4lzS3CCa2SiJ",
"updated": 1562867787
},
@joshuaaguilar20
Copy link
Author

//Working data Type - Has Name Key, and metadata

{
"id": "sku_FI59eqGzK6Lbt8",
"object": "product",
"active": true,
"attributes": [
"name"
],
"created": 1561055285,
"currency": "usd",
"image": "https://files.stripe.com/links/fl_live_7EJkEZ8wANKze0IclIf3bin3",
"inventory": {
"quantity": null,
"type": "infinite",
"value": null
},
"livemode": true,
"metadata": {
"Category": "Bracket",
"Dim": "13.25,1.25,13.25,0"
},
"package_dimensions": null,
"price": 1325,
"product": "prod_FI59vxQVfznIbH",
"updated": 1569541235,
"caption": null,
"deactivate_on": [],
"description": null,
"images": [],
"name": "CB-68",
"shippable": true,
"type": "good",
"url": null
},

@joshuaaguilar20
Copy link
Author

//Post Request To Fetch Next Set of 100 Products AWS Lambda

module.exports.handler = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const startingAfterID = requestBody.startingAfterId;
const startingAfterSku = requestBody.startingAfterSku;
return stripe.products.list({
limit: 100,
starting_after: startingAfterID
}).then((order) => {

    // Pay order with received token (from Stripe Checkout)
    return stripe.skus.list({
        limit: 100,
        starting_after: startingAfterSku
    }).then((price) => {
        const response = {
            statusCode: 200,
            headers: {
                'Access-Control-Allow-Origin': '*',
            },
            body: JSON.stringify({
                order: order.data,
                price: price.data
            }),
        };
        callback(null, response);
    })
})
    .catch((err) => { // Error response
        console.log(err);
        const response = {
            statusCode: 500,
            headers: {
                'Access-Control-Allow-Origin': '*',
            },
            body: JSON.stringify({
                error: err.message,
            }),
        };
        callback(null, response);
    })

};

@joshuaaguilar20
Copy link
Author

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
//Fetching first Products
module.exports.handler = (event, context, callback) => {

const productPrice = {};


return stripe.products.list({ limit: 100 }).then((order) => {


    return stripe.skus.list({ limit: 100 }).then((price) => {
        const response = {
            statusCode: 200,
            headers: {
                'Access-Control-Allow-Origin': '*',
            },
            body: JSON.stringify({
                order: order.data,
                price: price.data
            }),
        };
        callback(null, response);

    })
})
    .catch((err) => { // Error response
        console.log(err);
        const response = {
            statusCode: 500,
            headers: {
                'Access-Control-Allow-Origin': '*',
            },
            body: JSON.stringify({
                error: err.message,
            }),
        };
        callback(null, response);
    })

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment