-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
2,103 additions
and
1,853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ To support the different chapters and steps of the tutorial; we use branches to | |
- [Add a List All the Notes API](../../tree/add-a-list-all-the-notes-api) | ||
- [Add an Update Note API](../../tree/add-an-update-note-api) | ||
- [Add a Delete Note API](../../tree/add-a-delete-note-api) | ||
- [Unit Tests in Serverless](../../tree/unit-tests-in-serverless) | ||
|
||
#### Usage | ||
|
||
|
@@ -59,6 +60,6 @@ $ serverless deploy | |
|
||
#### Maintainers | ||
|
||
Serverless Stack is authored and maintained by Frank Wang ([@fanjiewang](https://twitter.com/fanjiewang)) & Jay V ([@jayair](https://twitter.com/jayair)). [**Subscribe to our newsletter**](http://eepurl.com/cEaBlf) for updates on Serverless Stack. Send us an [email][Email] if you have any questions. | ||
Serverless Stack is authored and maintained by Frank Wang ([@fanjiewang](https://twitter.com/fanjiewang)) & Jay V ([@jayair](https://twitter.com/jayair)). [**Subscribe to our newsletter**](https://emailoctopus.com/lists/1c11b9a8-1500-11e8-a3c9-06b79b628af2/forms/subscribe) for updates on Serverless Stack. Send us an [email][Email] if you have any questions. | ||
|
||
[Email]: mailto:[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import stripePackage from "stripe"; | ||
import { calculateCost } from "./libs/billing-lib"; | ||
import { success, failure } from "./libs/response-lib"; | ||
|
||
export async function main(event, context, callback) { | ||
const { storage, source } = JSON.parse(event.body); | ||
const amount = calculateCost(storage); | ||
const description = "Scratch charge"; | ||
|
||
// Load our secret key from the environment variables | ||
const stripe = stripePackage(process.env.stripeSecretKey); | ||
|
||
try { | ||
await stripe.charges.create({ | ||
source, | ||
amount, | ||
description, | ||
currency: "usd" | ||
}); | ||
callback(null, success({ status: true })); | ||
} catch (e) { | ||
callback(null, failure({ message: e.message })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function calculateCost(storage) { | ||
const rate = storage <= 10 | ||
? 4 | ||
: storage <= 100 | ||
? 2 | ||
: 1; | ||
|
||
return rate * storage * 100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"body": "{\"source\":\"tok_visa\",\"storage\":21}", | ||
"requestContext": { | ||
"identity": { | ||
"cognitoIdentityId": "USER-SUB-1234" | ||
} | ||
} | ||
} |
Oops, something went wrong.