Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stipe payment provider #25

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"pg-hstore": "^2.3.4",
"pino": "^8.11.0",
"prettier": "^2.5.1",
"stripe": "^10.8.0",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
61 changes: 61 additions & 0 deletions packages/server/src/payment_providers/stripe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import StripeApi from 'stripe';

import { Customer, Payment, Project, Subscription } from '~/entities';
import { PaymentProvider } from '~/payment_providers/types';

export class Stripe implements PaymentProvider {
api: StripeApi;

constructor({ apiKey }: { apiKey: string }) {
if (!apiKey) {
throw new Error('No api key');
}

this.api = new StripeApi(apiKey, {});
}

async startSubscription({
project,
redirectUrl,
payment,
}: {
project: Project;
subscription: Subscription;
redirectUrl: string;
payment: Payment;
}): Promise<{ checkoutUrl: string }> {
// TODO
const checkoutUrl = '';

return { checkoutUrl };
}

async chargePayment({ payment, project }: { payment: Payment; project: Project }): Promise<void> {
// TODO
}

async parsePaymentWebhook(
payload: unknown,
): Promise<{ paymentId: string; paidAt: Date | undefined; paymentStatus: 'pending' | 'paid' | 'failed' }> {
// TODO
return {
paymentStatus: 'failed',
paidAt: undefined,
paymentId: 'todo',
};
}

async createCustomer(customer: Customer): Promise<Customer> {
// TODO
return customer;
}

async updateCustomer(customer: Customer): Promise<Customer> {
// TODO
return customer;
}

async deleteCustomer(customer: Customer): Promise<void> {
// TODO
}
}
Loading
Loading