-
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.
Merge branch '147-booking-crud-service' of https://github.com/UoaWDCC…
…/uasc-web into 147-booking-crud-service
- Loading branch information
Showing
12 changed files
with
210 additions
and
32 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,38 @@ | ||
import { Controller, SuccessResponse, Route, Post, Request } from "tsoa" | ||
import Stripe from "stripe" | ||
|
||
@Route("webhook") | ||
export class StripeWebhook extends Controller { | ||
@Post() | ||
@SuccessResponse(200, "Webhook post received") | ||
public async receiveWebhook(@Request() request: any): Promise<void> { | ||
console.log("webhook received") | ||
|
||
const stripe = new Stripe(process.env.STRIPE_API_KEY) | ||
|
||
try { | ||
const event: Stripe.Event = stripe.webhooks.constructEvent( | ||
request.rawBody, | ||
request.headers["stripe-signature"], | ||
// process.env.STRIPE_LOCAL // test local api secret | ||
process.env.STRIPE_API_SECRET | ||
) | ||
switch (event.type) { | ||
case "payment_intent.succeeded": | ||
console.log("payment_intent.succeeded") | ||
break | ||
case "payment_method.attached": | ||
console.log("payment_method.attached") | ||
break | ||
default: | ||
console.log(`Unhandled event type ${event.type}.`) | ||
} | ||
|
||
return this.setStatus(200) // set status to 200 as success | ||
} catch (err) { | ||
console.error(err) | ||
// set status to 400 due to bad request | ||
return this.setStatus(400) | ||
} | ||
} | ||
} |
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,89 @@ | ||
import * as Stripe from "stripe" | ||
|
||
export const customerMock: Stripe.Stripe.Customer = { | ||
id: "cus_123456789", | ||
object: "customer", | ||
address: { | ||
city: "city", | ||
country: "NZ", | ||
line1: "line 1", | ||
line2: "line 2", | ||
postal_code: "90210", | ||
state: "Auckland" | ||
}, | ||
balance: 0, | ||
created: 1483565364, | ||
currency: null, | ||
default_source: null, | ||
delinquent: false, | ||
description: null, | ||
discount: null, | ||
email: null, | ||
invoice_prefix: "C11F7E1", | ||
invoice_settings: { | ||
custom_fields: null, | ||
default_payment_method: null, | ||
footer: null, | ||
rendering_options: null | ||
}, | ||
livemode: false, | ||
metadata: { | ||
order_id: "6735" | ||
}, | ||
name: null, | ||
next_invoice_sequence: 1, | ||
phone: null, | ||
preferred_locales: [], | ||
shipping: null, | ||
tax_exempt: "none" | ||
} | ||
|
||
export const productMock: Stripe.Stripe.Product = { | ||
id: "prod_NWjs8kKbJWmuuc", | ||
object: "product", | ||
active: true, | ||
created: 1678833149, | ||
default_price: null, | ||
description: null, | ||
images: [], | ||
features: [], | ||
livemode: false, | ||
metadata: {}, | ||
name: "Gold Plan", | ||
package_dimensions: null, | ||
shippable: null, | ||
statement_descriptor: null, | ||
tax_code: null, | ||
unit_label: null, | ||
updated: 1678833149, | ||
url: null, | ||
type: "good" | ||
} | ||
|
||
export const priceMock: Stripe.Stripe.Price = { | ||
id: "price_1MoBy5LkdIwHu7ixZhnattbh", | ||
object: "price", | ||
active: true, | ||
billing_scheme: "per_unit", | ||
created: 1679431181, | ||
currency: "usd", | ||
custom_unit_amount: null, | ||
livemode: false, | ||
lookup_key: null, | ||
metadata: {}, | ||
nickname: null, | ||
product: "prod_NZKdYqrwEYx6iK", | ||
recurring: { | ||
aggregate_usage: null, | ||
interval: "month", | ||
interval_count: 1, | ||
trial_period_days: null, | ||
usage_type: "licensed" | ||
}, | ||
tax_behavior: "unspecified", | ||
tiers_mode: null, | ||
transform_quantity: null, | ||
type: "recurring", | ||
unit_amount: 1000, | ||
unit_amount_decimal: "1000" | ||
} |
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