Skip to content

Commit

Permalink
Billing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeBellTMH committed Jan 31, 2021
1 parent 60f524c commit 1c0ec5a
Show file tree
Hide file tree
Showing 26 changed files with 3,406 additions and 39 deletions.
6 changes: 6 additions & 0 deletions amplify/backend/api/jcmobile/schema.graphql
Expand Up @@ -4,6 +4,8 @@ type Mutation {
createCustomer(idempotency:String,phone:String,email:String,firstName:String,lastName:String,billingAddress:StripeAddressInput): StripeCustomerData @function(name: "jcmobileStripCreateCustomer-${env}")
createSubscription(stripeCustomerID:String,stripeSubscriptionID:String,idempotency:String,paymentMethodId: String,priceInfo: StripePriceInput,freeDays:Int): StripeSubscriptionData @function(name: "jcmobileStripCreateSubscription-${env}")
previewInvoice(stripeCustomerID:String,idempotency:String,priceInfo: StripePriceInput): StripeInvoiceData @function(name: "jcmobileStripPreviewInvoice-${env}")
listInvoices(idempotency:String): StripeInvoicesListData @function(name: "jcmobileStripListInvoices-${env}")
cancelSubscription(idempotency:String): StripeSubscriptionData @function(name: "jcmobileStripCancelSubscription-${env}")
}
input StripeAddressInput
{
Expand All @@ -27,6 +29,10 @@ type StripeSubscriptionData{
type StripeInvoiceData{
invoice:StripeInvoice
}

type StripeInvoicesListData{
data:[StripeInvoice]
}
type StripeCustomerData{
customer:StripeCustomer
}
Expand Down
30 changes: 30 additions & 0 deletions amplify/backend/backend-config.json
Expand Up @@ -264,6 +264,36 @@
]
}
]
},
"jcmobileStripListInvoices": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda",
"dependsOn": [
{
"category": "api",
"resourceName": "jcmobile",
"attributes": [
"GraphQLAPIIdOutput",
"GraphQLAPIEndpointOutput"
]
}
]
},
"jcmobileStripCancelSubscription": {
"build": true,
"providerPlugin": "awscloudformation",
"service": "Lambda",
"dependsOn": [
{
"category": "api",
"resourceName": "jcmobile",
"attributes": [
"GraphQLAPIIdOutput",
"GraphQLAPIEndpointOutput"
]
}
]
}
},
"auth": {
Expand Down
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
@@ -0,0 +1,10 @@
{
"permissions": {
"api": {
"jcmobile": [
"read"
]
}
},
"lambdaLayers": []
}
@@ -0,0 +1,246 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Lambda Function resource stack creation using Amplify CLI",
"Parameters": {
"CloudWatchRule": {
"Type": "String",
"Default": "NONE",
"Description": " Schedule Expression"
},
"env": {
"Type": "String"
},
"apijcmobileGraphQLAPIIdOutput": {
"Type": "String",
"Default": "apijcmobileGraphQLAPIIdOutput"
},
"apijcmobileGraphQLAPIEndpointOutput": {
"Type": "String",
"Default": "apijcmobileGraphQLAPIEndpointOutput"
}
},
"Conditions": {
"ShouldNotCreateEnvResources": {
"Fn::Equals": [
{
"Ref": "env"
},
"NONE"
]
}
},
"Resources": {
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Metadata": {
"aws:asset:path": "./src",
"aws:asset:property": "Code"
},
"Properties": {
"Handler": "index.handler",
"FunctionName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"jcmobileStripCancelSubscription",
{
"Fn::Join": [
"",
[
"jcmobileStripCancelSubscription",
"-",
{
"Ref": "env"
}
]
]
}
]
},
"Environment": {
"Variables": {
"ENV": {
"Ref": "env"
},
"REGION": {
"Ref": "AWS::Region"
},
"API_JCMOBILE_GRAPHQLAPIIDOUTPUT": {
"Ref": "apijcmobileGraphQLAPIIdOutput"
},
"API_JCMOBILE_GRAPHQLAPIENDPOINTOUTPUT": {
"Ref": "apijcmobileGraphQLAPIEndpointOutput"
}
}
},
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Layers": [],
"Timeout": "25",
"Code": {
"S3Bucket": "amplify-jc-mobile-beta-155138-deployment",
"S3Key": "amplify-builds/jcmobileStripCancelSubscription-75582f56564346527639-build.zip"
}
}
},
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"jcmobileLambdaRole0452fd69",
{
"Fn::Join": [
"",
[
"jcmobileLambdaRole0452fd69",
"-",
{
"Ref": "env"
}
]
]
}
]
},
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
}
}
},
"lambdaexecutionpolicy": {
"DependsOn": [
"LambdaExecutionRole"
],
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "lambda-execution-policy",
"Roles": [
{
"Ref": "LambdaExecutionRole"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": {
"Fn::Sub": [
"arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:*",
{
"region": {
"Ref": "AWS::Region"
},
"account": {
"Ref": "AWS::AccountId"
},
"lambda": {
"Ref": "LambdaFunction"
}
}
]
}
}
]
}
}
},
"AmplifyResourcesPolicy": {
"DependsOn": [
"LambdaExecutionRole"
],
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "amplify-lambda-execution-policy",
"Roles": [
{
"Ref": "LambdaExecutionRole"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"appsync:Get*",
"appsync:List*"
],
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:appsync:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":apis/",
{
"Ref": "apijcmobileGraphQLAPIIdOutput"
},
"/*"
]
]
}
]
}
]
}
}
}
},
"Outputs": {
"Name": {
"Value": {
"Ref": "LambdaFunction"
}
},
"Arn": {
"Value": {
"Fn::GetAtt": [
"LambdaFunction",
"Arn"
]
}
},
"Region": {
"Value": {
"Ref": "AWS::Region"
}
},
"LambdaExecutionRole": {
"Value": {
"Ref": "LambdaExecutionRole"
}
}
}
}
@@ -0,0 +1 @@
{}
@@ -0,0 +1,5 @@
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
@@ -0,0 +1,15 @@


exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
// Uncomment below to enable CORS requests
// headers: {
// "Access-Control-Allow-Origin": "*",
// "Access-Control-Allow-Headers": "*"
// },
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,7 @@
{
"name": "jcmobileStripCancelSubscription",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0"
}
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
@@ -0,0 +1,10 @@
{
"permissions": {
"api": {
"jcmobile": [
"read"
]
}
},
"lambdaLayers": []
}

0 comments on commit 1c0ec5a

Please sign in to comment.