You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB
TypeScript

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from 'config';
@Injectable({
providedIn: 'root'
})
export class StripeService {
private apiUrl = 'https://api.stripe.com/v1';
private apiKey = environment.stripeApiKey; // Replace with your Stripe secret key
constructor(private http: HttpClient) { }
private getHeaders() {
const headers = new HttpHeaders()
.set('Authorization', `Bearer ${this.apiKey}`)
.set('Content-Type', 'application/x-www-form-urlencoded');
return { headers };
}
// Create payment link
createPaymentLink(priceId: string, quantity: string): Observable<any> {
const body = new URLSearchParams();
body.set('line_items[0][price]', priceId); // Add line_items parameter
body.set('line_items[0][quantity]', quantity); // Add line_items parameter
return this.http.post(`${this.apiUrl}/payment_links`, body.toString(), this.getHeaders());
}
}