-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions, fix menu, add admin screen
- Loading branch information
1 parent
6ca6855
commit c4357da
Showing
35 changed files
with
5,604 additions
and
305 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
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
74 changes: 74 additions & 0 deletions
74
amplify/backend/function/jcmobileShared/jcmobileShared-awscloudformation-template.json
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,74 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"7.6.15\",\"stackType\":\"function-LambdaLayer\",\"metadata\":{}}", | ||
"Parameters": { | ||
"env": { | ||
"Type": "String" | ||
}, | ||
"deploymentBucketName": { | ||
"Type": "String" | ||
}, | ||
"s3Key": { | ||
"Type": "String" | ||
}, | ||
"description": { | ||
"Type": "String", | ||
"Default": "" | ||
}, | ||
"runtimes": { | ||
"Type": "List<String>" | ||
} | ||
}, | ||
"Resources": { | ||
"LambdaLayerVersion2ffb38ed": { | ||
"Type": "AWS::Lambda::LayerVersion", | ||
"Properties": { | ||
"CompatibleRuntimes": { | ||
"Ref": "runtimes" | ||
}, | ||
"Content": { | ||
"S3Bucket": { | ||
"Ref": "deploymentBucketName" | ||
}, | ||
"S3Key": { | ||
"Ref": "s3Key" | ||
} | ||
}, | ||
"Description": { | ||
"Ref": "description" | ||
}, | ||
"LayerName": { | ||
"Fn::Sub": [ | ||
"jcmobileShared-${env}", | ||
{ | ||
"env": { | ||
"Ref": "env" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"DeletionPolicy": "Delete", | ||
"UpdateReplacePolicy": "Retain" | ||
}, | ||
"LambdaLayerPermissionPrivate2ffb38ed": { | ||
"Type": "AWS::Lambda::LayerVersionPermission", | ||
"Properties": { | ||
"Action": "lambda:GetLayerVersion", | ||
"LayerVersionArn": { | ||
"Ref": "LambdaLayerVersion2ffb38ed" | ||
}, | ||
"Principal": { | ||
"Ref": "AWS::AccountId" | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"Arn": { | ||
"Value": { | ||
"Ref": "LambdaLayerVersion2ffb38ed" | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
amplify/backend/function/jcmobileShared/layer-configuration.json
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,15 @@ | ||
{ | ||
"permissions": [ | ||
{ | ||
"type": "Private" | ||
} | ||
], | ||
"runtimes": [ | ||
{ | ||
"value": "nodejs", | ||
"name": "NodeJS", | ||
"runtimePluginId": "amplify-nodejs-function-runtime-provider", | ||
"layerExecutablePath": "nodejs" | ||
} | ||
] | ||
} |
193 changes: 193 additions & 0 deletions
193
amplify/backend/function/jcmobileShared/lib/nodejs/JCStripe.ts
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,193 @@ | ||
import Stripe from "stripe" | ||
export default class JCStripe { | ||
static async getSecret(name: string) { | ||
try { | ||
var AWS = require("aws-sdk"), | ||
region = "us-east-1", | ||
secretName = "jcmobile/" + process.env.ENV + "/secrets", | ||
secret, | ||
decodedBinarySecret | ||
|
||
// Create a Secrets Manager client | ||
var client = new AWS.SecretsManager({ | ||
region: region, | ||
}) | ||
const data = await client.getSecretValue({ SecretId: secretName }).promise() | ||
|
||
if ("SecretString" in data) { | ||
secret = JSON.parse(data.SecretString) | ||
} else { | ||
let buff = new Buffer(data.SecretBinary, "base64") | ||
decodedBinarySecret = buff.toString("ascii") | ||
} | ||
console.log("Loading Secret Done") | ||
|
||
return secret[name] | ||
} catch (e) { | ||
console.log({ error: e }) | ||
throw "Secret not loaded" | ||
} | ||
} | ||
static async createCustomer( | ||
customer: Stripe.CustomerCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.Customer>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const customerResult = await stripe.customers.create(customer, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return customerResult | ||
} | ||
static async updateCustomer( | ||
stripeCustomerID: string, | ||
customer: Stripe.CustomerUpdateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.Customer>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const customerResult = await stripe.customers.update(stripeCustomerID, customer, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return customerResult | ||
} | ||
|
||
static async createSetupIntent( | ||
setupIntent: Stripe.SetupIntentCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.SetupIntent>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const paymentMethodResult = await stripe.setupIntents.create(setupIntent, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return paymentMethodResult | ||
} | ||
static async createPaymentMethod( | ||
paymentMethod: Stripe.PaymentMethodCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.PaymentMethod>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const paymentMethodResult = await stripe.paymentMethods.create(paymentMethod, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return paymentMethodResult | ||
} | ||
static async listPaymentMethods( | ||
stripeCustomerID: string, | ||
type: Stripe.PaymentMethodListParams.Type | ||
): Promise<Stripe.Response<Stripe.ApiList<Stripe.PaymentMethod>>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const customerResult = await stripe.paymentMethods.list({ | ||
customer: stripeCustomerID, | ||
type: type, | ||
}) | ||
return customerResult | ||
} | ||
static async getPaymentMethod( | ||
paymentMethodId: string | ||
): Promise<Stripe.Response<Stripe.PaymentMethod>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const customerResult = await stripe.paymentMethods.retrieve(paymentMethodId) | ||
return customerResult | ||
} | ||
static async detatchPaymentMethod( | ||
paymentMethodId: string | ||
): Promise<Stripe.Response<Stripe.PaymentMethod>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const customerResult = await stripe.paymentMethods.detach(paymentMethodId) | ||
return customerResult | ||
} | ||
static async createInvoiceItem( | ||
payment: Stripe.InvoiceItemCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.InvoiceItem>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.invoiceItems.create(payment, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
static async createInvoice( | ||
payment: Stripe.InvoiceCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.Invoice>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.invoices.create(payment, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
static async createPayment( | ||
payment: Stripe.PaymentIntentCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.PaymentIntent>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.paymentIntents.create(payment, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
static async createSubscription( | ||
subscription: Stripe.SubscriptionCreateParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.Subscription>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.subscriptions.create(subscription, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
static async getSubscription( | ||
subscriptionId: string | ||
): Promise<Stripe.Response<Stripe.Subscription>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.subscriptions.retrieve(subscriptionId) | ||
return subscriptionResult | ||
} | ||
static async deleteSubscription( | ||
subscriptionId: string, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.Subscription>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.subscriptions.del(subscriptionId, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
static async listSubscription( | ||
subscription: Stripe.SubscriptionListParams, | ||
idempotency: string | ||
): Promise<Stripe.Response<Stripe.ApiList<Stripe.Subscription>>> { | ||
const stripe = new Stripe(await this.getSecret("stripeSecret"), { | ||
apiVersion: "2020-08-27", | ||
}) | ||
const subscriptionResult = await stripe.subscriptions.list(subscription, { | ||
idempotencyKey: idempotency + "CC", | ||
}) | ||
return subscriptionResult | ||
} | ||
} |
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 @@ | ||
Replace this file with your layer files |
29 changes: 29 additions & 0 deletions
29
amplify/backend/function/jcmobileShared/lib/nodejs/package.json
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,29 @@ | ||
{ | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.ts", | ||
"dependencies": { | ||
"@aws-amplify/api": "^4.0.5", | ||
"@aws-amplify/auth": "^4.1.1", | ||
"@aws-amplify/core": "^4.1.3", | ||
"@babel/plugin-transform-typescript": "^7.14.6", | ||
"@babel/preset-flow": "^7.14.5", | ||
"babel-plugin-add-module-exports": "^1.0.4", | ||
"node-fetch": "^2.6.1", | ||
"stripe": "^8.125.0" | ||
}, | ||
"scripts": { | ||
"compile": "tsc", | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.14.5", | ||
"@babel/core": "^7.14.6", | ||
"@babel/preset-env": "7.14.5", | ||
"@types/aws-lambda": "^8.10.51", | ||
"@types/domhandler": "2.4.2", | ||
"@types/node": "^16.3.1", | ||
"aws-sdk": "^2.953.0", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
Oops, something went wrong.