File

src/core/stripe/stripe.service.ts

Index

Properties
Methods

Methods

Async confirmPaymentIntents
confirmPaymentIntents(id: string)
Parameters :
Name Type Optional
id string No
Returns : Promise<Stripe.paymentIntents.IPaymentIntent>
Async createPaymentIntents
createPaymentIntents(amount: number, paymentMethodID: string, statementDescriptor, returnUrl: string)
Parameters :
Name Type Optional
amount number No
paymentMethodID string No
statementDescriptor No
returnUrl string No
Returns : Promise<Stripe.paymentIntents.IPaymentIntent>
Async createPaymentMethods
createPaymentMethods(cardNumber: string, expMonth: number, expYear: number, cvc: string)
Parameters :
Name Type Optional
cardNumber string No
expMonth number No
expYear number No
cvc string No
Returns : Promise<Stripe.paymentMethods.IPaymentMethod>
Async retrievePaymentIntents
retrievePaymentIntents(id: string)
Parameters :
Name Type Optional
id string No
Returns : Promise<Stripe.paymentIntents.IPaymentIntent>

Properties

Private Readonly stripe
Default value : new Stripe(process.env.STRIPE_OG_TEST)
import { Injectable } from '@nestjs/common';
import * as Stripe from 'stripe';

@Injectable()
export class StripeService {
  private readonly stripe = new Stripe(process.env.STRIPE_OG_TEST);

  async createPaymentIntents(
    amount: number,
    paymentMethodID: string,
    statementDescriptor,
    returnUrl: string
  ): Promise<Stripe.paymentIntents.IPaymentIntent> {
    return this.stripe.paymentIntents.create({
      amount,
      currency: 'gbp',
      statement_descriptor: statementDescriptor,
      payment_method: paymentMethodID,
      confirmation_method: 'manual',
      confirm: true,
      return_url: returnUrl,
    });
  }

  async createPaymentMethods(
    cardNumber: string,
    expMonth: number,
    expYear: number,
    cvc: string
  ): Promise<Stripe.paymentMethods.IPaymentMethod> {
    return this.stripe.paymentMethods.create({
      type: 'card',
      card: {
        cvc,
        number: cardNumber,
        exp_month: expMonth,
        exp_year: expYear,
      },
    });
  }

  async retrievePaymentIntents(
    id: string
  ): Promise<Stripe.paymentIntents.IPaymentIntent> {
    return this.stripe.paymentIntents.retrieve(id);
  }

  async confirmPaymentIntents(
    id: string
  ): Promise<Stripe.paymentIntents.IPaymentIntent> {
    return this.stripe.paymentIntents.confirm(id);
  }
}

results matching ""

    No results matching ""