{"version":3,"sources":["src/app/services/stripe/index.ts"],"sourcesContent":["import { HttpClient, HttpErrorResponse } from '@angular/common/http'\nimport { Injectable } from '@angular/core'\nimport { Observable, of, throwError } from 'rxjs'\nimport { catchError } from 'rxjs/operators'\nimport {\n CheckoutSessionResponse,\n CreateCustomerPortal,\n CreatePortalSessionResponse,\n Price,\n Product,\n StripeCustomer,\n UpdateCustomerDto,\n UserSubscription,\n UserSubscriptionsResponse,\n} from 'src/app/models/stripe-payments.model'\nimport { environment } from 'src/environments/environment'\n\n@Injectable()\nexport class StripePaymentsService {\n private errorMessage: string = 'Unknow error'\n constructor(private http: HttpClient) {}\n\n getProducts(): Observable {\n return this.http\n .get(`${environment.apiBaseUrl}/payments/products`)\n .pipe(catchError(this.handleError))\n }\n\n getPricesByProductId(productId: string): Observable {\n return this.http\n .get(`${environment.apiBaseUrl}/payments/prices/${productId}`)\n .pipe(catchError(this.handleError))\n }\n\n getUserSubscriptions(userEmail: string): Observable {\n return this.http\n .get(`${environment.apiBaseUrl}/payments/subscriptions/email/${userEmail}`)\n .pipe(catchError(this.handleError))\n }\n\n updateUserMetadata(body: UpdateCustomerDto): Observable {\n return this.http\n .patch(`${environment.apiBaseUrl}/payments/customer`, body)\n .pipe(catchError(this.handleError))\n }\n\n cancelSubscription(subscriptionId: string): Observable {\n const body = {\n subscription: subscriptionId,\n immediatelly: false,\n }\n return this.http\n .patch(`${environment.apiBaseUrl}/payments/subscription/cancel`, body)\n .pipe(catchError(this.handleError))\n }\n\n revertSubscriptionCancelation(subscriptionId: string): Observable {\n const body = {\n subscription: subscriptionId,\n // immediatelly: false\n }\n return this.http\n .patch(`${environment.apiBaseUrl}/payments/subscription/reactivate`, body)\n .pipe(catchError(this.handleError))\n }\n\n createCheckoutSession(priceId: string, customerId: string): Observable {\n const body = {\n // customer_email: userEmail,\n customer: customerId,\n success_url: environment.STRIPE_PAYMENTS.successUrl,\n cancel_url: environment.STRIPE_PAYMENTS.cancelUrl,\n line_items: [{ price: priceId, quantity: 1 }],\n mode: 'subscription',\n }\n return this.http\n .post(`${environment.apiBaseUrl}/payments/checkoutsession`, body)\n .pipe(catchError(this.handleError))\n }\n\n createCustomerPortalSession(\n input: Omit,\n ): Observable {\n const body: CreateCustomerPortal = {\n ...input,\n return_url: environment.STRIPE_PAYMENTS.successUrl,\n }\n return this.http\n .post(`${environment.apiBaseUrl}/payments/customerportal`, body)\n .pipe(catchError(this.handleError.bind(this)))\n }\n\n setErrorMessage(message: string): void {\n this.errorMessage = message ?? this.errorMessage\n }\n\n getErrorMessage(): string {\n return this.errorMessage\n }\n\n handleError(error: HttpErrorResponse): Observable {\n const {\n error: { description, code, error: e },\n } = error\n this.setErrorMessage(description ?? e ?? this.errorMessage)\n return of(null)\n }\n}\n"],"names":["StripePaymentsService","constructor","http","errorMessage","getProducts","get","environment","apiBaseUrl","pipe","catchError","handleError","getPricesByProductId","productId","getUserSubscriptions","userEmail","updateUserMetadata","body","patch","cancelSubscription","subscriptionId","subscription","immediatelly","revertSubscriptionCancelation","createCheckoutSession","priceId","customerId","customer","success_url","STRIPE_PAYMENTS","successUrl","cancel_url","cancelUrl","line_items","price","quantity","mode","post","createCustomerPortalSession","input","__spreadProps","__spreadValues","return_url","bind","setErrorMessage","message","getErrorMessage","error","description","code","e","of","ɵɵinject","HttpClient","factory","ɵfac"],"mappings":";;sFAkBA,IAAaA,GAAqB,IAAA,CAA5B,MAAOA,CAAqB,CAEhCC,YAAoBC,EAAgB,CAAhB,KAAAA,KAAAA,EADZ,KAAAC,aAAuB,cACQ,CAEvCC,aAAW,CACT,OAAO,KAAKF,KACTG,IAAe,GAAGC,EAAYC,UAAU,oBAAoB,EAC5DC,KAAKC,EAAW,KAAKC,WAAW,CAAC,CACtC,CAEAC,qBAAqBC,EAAiB,CACpC,OAAO,KAAKV,KACTG,IAAe,GAAGC,EAAYC,UAAU,oBAAoBK,CAAS,EAAE,EACvEJ,KAAKC,EAAW,KAAKC,WAAW,CAAC,CACtC,CAEAG,qBAAq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