update payment method

This commit is contained in:
Damodar Lohani
2023-02-10 11:02:08 +05:45
parent 0a7f87383f
commit bef77eaabd
2 changed files with 24 additions and 12 deletions
+7 -8
View File
@@ -27,19 +27,18 @@ export class Billing {
);
}
async updatePaymentMethod(teamId: string, paymentMethodId: string) {
const path = `/teams/${teamId}/payment-methods/${paymentMethodId}`;
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('PUT', uri, { 'content-type': 'application/json' }, {});
}
async updateProjectPlan(projectId: string, billingPlan: string) {
const path = `/project/${projectId}/plan`;
const params: Payload = {
billingPlan
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'patch',
uri,
{
'content-type': 'application/json'
},
params
);
return await this.client.call('patch', uri, { 'content-type': 'application/json' }, params);
}
}
@@ -16,6 +16,7 @@
let showDelete = false;
let stripe: any;
let elements: any;
let paymentMethod: any;
onMount(() => {
name = $organization.name;
@@ -30,7 +31,7 @@
event.preventDefault();
try {
const paymentMethod = await cloudSdk.billing.createPaymentMethod($organization.$id);
paymentMethod = await cloudSdk.billing.createPaymentMethod($organization.$id);
const options = {
clientSecret: paymentMethod.clientSecret,
// Fully customizable with appearance API.
@@ -69,9 +70,21 @@
type: 'error'
});
} else {
// Your customer will be redirected to your `return_url`. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
if (paymentMethod) {
const { error, setupIntent } = await stripe.retrieveSetupIntent(
paymentMethod.clientSecret
);
if (error) {
addNotification({
message: error.message,
type: 'error'
});
} else if (setupIntent && setupIntent.status === 'succeeded') {
//update payment method
cloudSdk.billing.updatePaymentMethod($organization.$id, paymentMethod.$id);
}
}
}
}