Skip to content

Commit

Permalink
chore: Merge pull request #119 from eventOneHQ/master
Browse files Browse the repository at this point in the history
3.0.0-beta.7
  • Loading branch information
nprail authored Mar 24, 2023
2 parents 6d7e332 + 6fe11ef commit 42c45b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export interface PaymentIntent {
/**
* The payment method to be used in this `PaymentIntent`. Only valid in the intent returned during `collectPaymentMethod` when using the `updatePaymentIntent` option in the `CollectConfig`.
*/
paymentMethod: Stripe.PaymentMethod | null
paymentMethod: Stripe.PaymentMethod | string | null

/**
* Details about items included in the amount after confirmation.
Expand Down
26 changes: 8 additions & 18 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,10 @@ export class StripeTerminalPlugin {
})
}

private parseJson(json: string, name: string): any {
try {
const jsonObj = JSON.parse(json)
private parseJson(json: string): any {
const jsonObj = JSON.parse(json)

return this.snakeCaseRecursively(jsonObj)
} catch (err) {
console.error(`Error parsing ${name} JSON`, err)
return null
}
return this.snakeCaseRecursively(jsonObj)
}

private normalizePaymentIntent(paymentIntent: any): PaymentIntent | null {
Expand All @@ -404,26 +399,21 @@ export class StripeTerminalPlugin {
paymentIntent.amountDetails &&
typeof paymentIntent.amountDetails === 'string'
) {
paymentIntent.amountDetails = this.parseJson(
paymentIntent.amountDetails,
'PaymentIntent.amountDetails'
)
paymentIntent.amountDetails = this.parseJson(paymentIntent.amountDetails)
}

if (
paymentIntent.paymentMethod &&
typeof paymentIntent.paymentMethod === 'string'
typeof paymentIntent.paymentMethod === 'string' &&
!paymentIntent.paymentMethod.startsWith('pm_') // if its just the ID, return the ID
) {
paymentIntent.paymentMethod = this.parseJson(
paymentIntent.paymentMethod,
'PaymentIntent.paymentMethod'
)
paymentIntent.paymentMethod = this.parseJson(paymentIntent.paymentMethod)
}

if (paymentIntent.charges) {
paymentIntent.charges = paymentIntent.charges.map((charge: any) => {
if (typeof charge === 'string') {
return this.parseJson(charge, 'PaymentIntent.charges')
return this.parseJson(charge)
}

return charge
Expand Down

0 comments on commit 42c45b0

Please sign in to comment.