//native
type Paypal = {
clientId: string;
clientSecret: string;
};
async function getToken(auth: Paypal): Promise<string> {
const url = new URL(`https://api-m.paypal.com/v1/oauth2/token`);
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Basic ${btoa(`${auth.clientId}:${auth.clientSecret}`)}`,
},
body: new URLSearchParams({
grant_type: "client_credentials",
}),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`Could not get token: ${response.status} ${text}`);
}
const json = await response.json();
return json.access_token;
}
/**
* Create batch payout
* Creates a batch payout.
*/
export async function main(
auth: Paypal,
PayPal_Request_Id: string,
body: {
sender_batch_header: {
sender_batch_id?: string;
recipient_type?: string;
email_subject?: string;
email_message?: string;
note?: string;
};
items: {
recipient_type?: string;
amount: { currency: string; value: string };
note?: string;
receiver: string;
sender_item_id?: string;
recipient_wallet?: string;
alternate_notification_method?: {
phone?: {
country_code: string;
national_number: string;
extension_number?: string;
};
};
notification_language?: string;
application_context?: {
social_feed_privacy?: string;
holler_url?: string;
logo_url?: string;
};
purpose?:
| "AWARDS"
| "PRIZES"
| "DONATIONS"
| "GOODS"
| "SERVICES"
| "REBATES"
| "CASHBACK"
| "DISCOUNTS"
| "NON_GOODS_OR_SERVICES";
}[];
},
) {
const token = await getToken(auth);
const url = new URL(`https://api-m.paypal.com/v1/payments/payouts`);
const response = await fetch(url, {
method: "POST",
headers: {
"PayPal-Request-Id": PayPal_Request_Id,
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago
//native
type Paypal = {
token: string;
};
/**
* Create batch payout
* Creates a batch payout.
*/
export async function main(
auth: Paypal,
PayPal_Request_Id: string,
body: {
sender_batch_header: {
sender_batch_id?: string;
recipient_type?: string;
email_subject?: string;
email_message?: string;
note?: string;
};
items: {
recipient_type?: string;
amount: { currency: string; value: string };
note?: string;
receiver: string;
sender_item_id?: string;
recipient_wallet?: string;
alternate_notification_method?: {
phone?: {
country_code: string;
national_number: string;
extension_number?: string;
};
};
notification_language?: string;
application_context?: {
social_feed_privacy?: string;
holler_url?: string;
logo_url?: string;
};
purpose?:
| "AWARDS"
| "PRIZES"
| "DONATIONS"
| "GOODS"
| "SERVICES"
| "REBATES"
| "CASHBACK"
| "DISCOUNTS"
| "NON_GOODS_OR_SERVICES";
}[];
},
) {
const url = new URL(`https://api-m.paypal.com/v1/payments/payouts`);
const response = await fetch(url, {
method: "POST",
headers: {
"PayPal-Request-Id": PayPal_Request_Id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago