* mv PaymentPage to web * mv 2 more components to web * refactor * update imports * mv * revert * fix * fix * update * migrate relevant test too * move setup components to web from appstore * move wipemycalother * mv * fix typechecks * mv more routing forms components * fix * fix * fix * fix: resolve type errors in SingleForm.tsx after migration - Updated SingleFormComponentProps type to include enriched form properties - Added proper typing for user, team, nonOrgUsername, nonOrgTeamslug, userOrigin, teamOrigin - Fixes type errors that occurred after migrating SingleForm.tsx from packages/app-store/routing-forms/components/ - Resolves both SingleForm.tsx and TestForm.tsx type errors Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * delete * refactors * fix * fix * fix * remove usage of trpc client from OmniInstallAppButton.tsx * fix test * import only type * fix test * remove trpc package from appstore package.json * remove remaining trpc usage * update test * fix type checks * fix errors * fix * make it error * nit --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import Paypal from "./Paypal";
|
|
|
|
const schema = z.object({
|
|
credentialId: z.coerce.number(),
|
|
key: z.object({
|
|
client_id: z.string(),
|
|
secret_key: z.string(),
|
|
}),
|
|
});
|
|
|
|
type TUpdateAppCredentialsInputSchema = { credentialId: number; key: { [k: string]: unknown } };
|
|
|
|
const handlePaypalValidations = async ({ input }: { input: TUpdateAppCredentialsInputSchema }) => {
|
|
const validated = schema.safeParse(input);
|
|
if (!validated.success) throw new Error("Invalid input");
|
|
const { key } = validated.data;
|
|
|
|
// Test credentials before saving
|
|
const paypalClient = new Paypal({ clientId: key.client_id, secretKey: key.secret_key });
|
|
const test = await paypalClient.test();
|
|
if (!test) throw new Error("Provided credentials failed to authenticate");
|
|
|
|
// Delete all existing webhooks
|
|
const webhooksToDelete = await paypalClient.listWebhooks();
|
|
if (webhooksToDelete) {
|
|
const promises = webhooksToDelete.map((webhook) => paypalClient.deleteWebhook(webhook));
|
|
await Promise.all(promises);
|
|
}
|
|
|
|
// Create webhook for this installation
|
|
const webhookId = await paypalClient.createWebhook();
|
|
if (!webhookId) {
|
|
// @TODO: make a button that tries to create the webhook again
|
|
console.error("Failed to create webhook", webhookId);
|
|
throw new Error("Failed to create webhook");
|
|
}
|
|
|
|
return {
|
|
client_id: key.client_id,
|
|
secret_key: key.secret_key,
|
|
webhook_id: webhookId,
|
|
};
|
|
};
|
|
|
|
export default handlePaypalValidations;
|