Edits history of script submission #12735 for ' Create partner referral (paypal)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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 partner referral
     * Creates a partner referral that is shared by the partner or API caller. The partner referral is used to onboard the seller, and contains the seller's personal, business, financial and operations.
     */
    export async function main(
      auth: Paypal,
      body: {
        individual_owners?: {
          id?: string;
          names?: {
            prefix?: string;
            given_name?: string;
            surname?: string;
            middle_name?: string;
            suffix?: string;
            full_name?: string;
          } & { type?: "LEGAL" }[];
          citizenship?: string;
          addresses?: {
            address_line_1?: string;
            address_line_2?: string;
            address_line_3?: string;
            admin_area_4?: string;
            admin_area_3?: string;
            admin_area_2?: string;
            admin_area_1?: string;
            postal_code?: string;
            country_code: string;
            address_details?: {
              street_number?: string;
              street_name?: string;
              street_type?: string;
              delivery_service?: string;
              building_name?: string;
              sub_building?: string;
            };
          } & { type?: "HOME"; primary?: false | true; inactive?: false | true }[];
          phones?: {
            country_code: string;
            national_number: string;
            extension_number?: string;
          } & {
            contact_name?: string;
            inactive?: false | true;
            primary?: false | true;
            primary_mobile?: false | true;
            type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
            tags?: "MOBILE" | "LANDLINE"[];
          }[];
          birth_details?: { date_of_birth: string };
          documents?: {
            id?: string;
            labels?: string[];
            name?: string;
            identification_number?: string;
            issue_date?: string;
            expiry_date?: string;
            issuing_country_code?: string;
            files?: {
              id?: string;
              reference_url?: string;
              content_type?: string;
              create_time?: string;
              size?: string;
            }[];
            links?: {
              href: string;
              rel: string;
              method?:
                | "GET"
                | "POST"
                | "PUT"
                | "DELETE"
                | "HEAD"
                | "CONNECT"
                | "OPTIONS"
                | "PATCH";
            }[];
          } & {
            type?:
              | "SOCIAL_SECURITY_NUMBER"
              | "EMPLOYMENT_IDENTIFICATION_NUMBER"
              | "TAX_IDENTIFICATION_NUMBER"
              | "PASSPORT_NUMBER"
              | "PENSION_FUND_ID"
              | "MEDICAL_INSURANCE_ID"
              | "CNPJ"
              | "CPF"
              | "PAN";
          }[];
        } & { type?: "PRIMARY" }[];
        business_entity?: {
          business_type?: {
            type?:
              | "ANY_OTHER_BUSINESS_ENTITY"
              | "ASSOCIATION"
              | "CORPORATION"
              | "GENERAL_PARTNERSHIP"
              | "GOVERNMENT"
              | "INDIVIDUAL"
              | "LIMITED_LIABILITY_PARTNERSHIP"
              | "LIMITED_LIABILITY_PROPRIETORS"
              | "LIMITED_LIABILITY_PRIVATE_CORPORATION"
              | "LIMITED_PARTNERSHIP"
              | "LIMITED_PARTNERSHIP_PRIVATE_CORPORATION"
              | "NONPROFIT"
              | "ONLY_BUY_OR_SEND_MONEY"
              | "OTHER_CORPORATE_BODY"
              | "PARTNERSHIP"
              | "PRIVATE_PARTNERSHIP"
              | "PROPRIETORSHIP"
              | "PROPRIETORSHIP_CRAFTSMAN"
              | "PROPRIETORY_COMPANY"
              | "PRIVATE_CORPORATION"
              | "PUBLIC_COMPANY"
              | "PUBLIC_CORPORATION"
              | "PUBLIC_PARTNERSHIP"
              | "REGISTERED_COOPERATIVE";
            subtype?:
              | "ASSO_TYPE_INCORPORATED"
              | "ASSO_TYPE_NON_INCORPORATED"
              | "GOVT_TYPE_ENTITY"
              | "GOVT_TYPE_EMANATION"
              | "GOVT_TYPE_ESTD_COMM"
              | "GOVT_TYPE_ESTD_FC"
              | "GOVT_TYPE_ESTD_ST_TR";
          };
          business_industry?: {
            category: string;
            mcc_code: string;
            subcategory: string;
          };
          business_incorporation?: {
            incorporation_country_code?: string;
            incorporation_date?: string;
            incorporation_province_code?: string;
          };
          names?: { business_name?: string } & {
            id?: string;
            type?: "DOING_BUSINESS_AS" | "LEGAL_NAME";
          }[];
          emails?: { type: "CUSTOMER_SERVICE"; email: string }[];
          website?: string;
          addresses?: {
            address_line_1?: string;
            address_line_2?: string;
            address_line_3?: string;
            admin_area_4?: string;
            admin_area_3?: string;
            admin_area_2?: string;
            admin_area_1?: string;
            postal_code?: string;
            country_code: string;
            address_details?: {
              street_number?: string;
              street_name?: string;
              street_type?: string;
              delivery_service?: string;
              building_name?: string;
              sub_building?: string;
            };
          } & { type?: "WORK"; primary?: false | true; inactive?: false | true }[];
          phones?: {
            country_code: string;
            national_number: string;
            extension_number?: string;
          } & {
            contact_name?: string;
            inactive?: false | true;
            primary?: false | true;
            type?: "CUSTOMER_SERVICE" | "BUSINESS";
            tags?: "MOBILE" | "LANDLINE"[];
          }[];
          documents?: {
            id?: string;
            labels?: string[];
            name?: string;
            identification_number?: string;
            issue_date?: string;
            expiry_date?: string;
            issuing_country_code?: string;
            files?: {
              id?: string;
              reference_url?: string;
              content_type?: string;
              create_time?: string;
              size?: string;
            }[];
            links?: {
              href: string;
              rel: string;
              method?:
                | "GET"
                | "POST"
                | "PUT"
                | "DELETE"
                | "HEAD"
                | "CONNECT"
                | "OPTIONS"
                | "PATCH";
            }[];
          } & {
            type?:
              | "SOCIAL_SECURITY_NUMBER"
              | "EMPLOYMENT_IDENTIFICATION_NUMBER"
              | "TAX_IDENTIFICATION_NUMBER"
              | "PASSPORT_NUMBER"
              | "PENSION_FUND_ID"
              | "MEDICAL_INSURANCE_ID"
              | "CNPJ"
              | "CPF"
              | "PAN";
          }[];
        } & {
          beneficial_owners?: {
            individual_beneficial_owners?: {
              id?: string;
              names?: {
                prefix?: string;
                given_name?: string;
                surname?: string;
                middle_name?: string;
                suffix?: string;
                full_name?: string;
              } & { type?: "LEGAL" }[];
              citizenship?: string;
              addresses?: {
                address_line_1?: string;
                address_line_2?: string;
                address_line_3?: string;
                admin_area_4?: string;
                admin_area_3?: string;
                admin_area_2?: string;
                admin_area_1?: string;
                postal_code?: string;
                country_code: string;
                address_details?: {
                  street_number?: string;
                  street_name?: string;
                  street_type?: string;
                  delivery_service?: string;
                  building_name?: string;
                  sub_building?: string;
                };
              } & {
                type?: "HOME";
                primary?: false | true;
                inactive?: false | true;
              }[];
              phones?: {
                country_code: string;
                national_number: string;
                extension_number?: string;
              } & {
                contact_name?: string;
                inactive?: false | true;
                primary?: false | true;
                primary_mobile?: false | true;
                type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
                tags?: "MOBILE" | "LANDLINE"[];
              }[];
              birth_details?: { date_of_birth: string };
              documents?: {
                id?: string;
                labels?: string[];
                name?: string;
                identification_number?: string;
                issue_date?: string;
                expiry_date?: string;
                issuing_country_code?: string;
                files?: {
                  id?: string;
                  reference_url?: string;
                  content_type?: string;
                  create_time?: string;
                  size?: string;
                }[];
                links?: {
                  href: string;
                  rel: string;
                  method?:
                    | "GET"
                    | "POST"
                    | "PUT"
                    | "DELETE"
                    | "HEAD"
                    | "CONNECT"
                    | "OPTIONS"
                    | "PATCH";
                }[];
              } & {
                type?:
                  | "SOCIAL_SECURITY_NUMBER"
                  | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                  | "TAX_IDENTIFICATION_NUMBER"
                  | "PASSPORT_NUMBER"
                  | "PENSION_FUND_ID"
                  | "MEDICAL_INSURANCE_ID"
                  | "CNPJ"
                  | "CPF"
                  | "PAN";
              }[];
            } & { percentage_of_ownership?: string }[];
            business_beneficial_owners?: {
              business_type?: {
                type?:
                  | "ANY_OTHER_BUSINESS_ENTITY"
                  | "ASSOCIATION"
                  | "CORPORATION"
                  | "GENERAL_PARTNERSHIP"
                  | "GOVERNMENT"
                  | "INDIVIDUAL"
                  | "LIMITED_LIABILITY_PARTNERSHIP"
                  | "LIMITED_LIABILITY_PROPRIETORS"
                  | "LIMITED_LIABILITY_PRIVATE_CORPORATION"
                  | "LIMITED_PARTNERSHIP"
                  | "LIMITED_PARTNERSHIP_PRIVATE_CORPORATION"
                  | "NONPROFIT"
                  | "ONLY_BUY_OR_SEND_MONEY"
                  | "OTHER_CORPORATE_BODY"
                  | "PARTNERSHIP"
                  | "PRIVATE_PARTNERSHIP"
                  | "PROPRIETORSHIP"
                  | "PROPRIETORSHIP_CRAFTSMAN"
                  | "PROPRIETORY_COMPANY"
                  | "PRIVATE_CORPORATION"
                  | "PUBLIC_COMPANY"
                  | "PUBLIC_CORPORATION"
                  | "PUBLIC_PARTNERSHIP"
                  | "REGISTERED_COOPERATIVE";
                subtype?:
                  | "ASSO_TYPE_INCORPORATED"
                  | "ASSO_TYPE_NON_INCORPORATED"
                  | "GOVT_TYPE_ENTITY"
                  | "GOVT_TYPE_EMANATION"
                  | "GOVT_TYPE_ESTD_COMM"
                  | "GOVT_TYPE_ESTD_FC"
                  | "GOVT_TYPE_ESTD_ST_TR";
              };
              business_industry?: {
                category: string;
                mcc_code: string;
                subcategory: string;
              };
              business_incorporation?: {
                incorporation_country_code?: string;
                incorporation_date?: string;
                incorporation_province_code?: string;
              };
              names?: { business_name?: string } & {
                id?: string;
                type?: "DOING_BUSINESS_AS" | "LEGAL_NAME";
              }[];
              emails?: { type: "CUSTOMER_SERVICE"; email: string }[];
              website?: string;
              addresses?: {
                address_line_1?: string;
                address_line_2?: string;
                address_line_3?: string;
                admin_area_4?: string;
                admin_area_3?: string;
                admin_area_2?: string;
                admin_area_1?: string;
                postal_code?: string;
                country_code: string;
                address_details?: {
                  street_number?: string;
                  street_name?: string;
                  street_type?: string;
                  delivery_service?: string;
                  building_name?: string;
                  sub_building?: string;
                };
              } & {
                type?: "WORK";
                primary?: false | true;
                inactive?: false | true;
              }[];
              phones?: {
                country_code: string;
                national_number: string;
                extension_number?: string;
              } & {
                contact_name?: string;
                inactive?: false | true;
                primary?: false | true;
                type?: "CUSTOMER_SERVICE" | "BUSINESS";
                tags?: "MOBILE" | "LANDLINE"[];
              }[];
              documents?: {
                id?: string;
                labels?: string[];
                name?: string;
                identification_number?: string;
                issue_date?: string;
                expiry_date?: string;
                issuing_country_code?: string;
                files?: {
                  id?: string;
                  reference_url?: string;
                  content_type?: string;
                  create_time?: string;
                  size?: string;
                }[];
                links?: {
                  href: string;
                  rel: string;
                  method?:
                    | "GET"
                    | "POST"
                    | "PUT"
                    | "DELETE"
                    | "HEAD"
                    | "CONNECT"
                    | "OPTIONS"
                    | "PATCH";
                }[];
              } & {
                type?:
                  | "SOCIAL_SECURITY_NUMBER"
                  | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                  | "TAX_IDENTIFICATION_NUMBER"
                  | "PASSPORT_NUMBER"
                  | "PENSION_FUND_ID"
                  | "MEDICAL_INSURANCE_ID"
                  | "CNPJ"
                  | "CPF"
                  | "PAN";
              }[];
            } & { percentage_of_ownership?: string }[];
          };
          office_bearers?: {
            id?: string;
            names?: {
              prefix?: string;
              given_name?: string;
              surname?: string;
              middle_name?: string;
              suffix?: string;
              full_name?: string;
            } & { type?: "LEGAL" }[];
            citizenship?: string;
            addresses?: {
              address_line_1?: string;
              address_line_2?: string;
              address_line_3?: string;
              admin_area_4?: string;
              admin_area_3?: string;
              admin_area_2?: string;
              admin_area_1?: string;
              postal_code?: string;
              country_code: string;
              address_details?: {
                street_number?: string;
                street_name?: string;
                street_type?: string;
                delivery_service?: string;
                building_name?: string;
                sub_building?: string;
              };
            } & {
              type?: "HOME";
              primary?: false | true;
              inactive?: false | true;
            }[];
            phones?: {
              country_code: string;
              national_number: string;
              extension_number?: string;
            } & {
              contact_name?: string;
              inactive?: false | true;
              primary?: false | true;
              primary_mobile?: false | true;
              type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
              tags?: "MOBILE" | "LANDLINE"[];
            }[];
            birth_details?: { date_of_birth: string };
            documents?: {
              id?: string;
              labels?: string[];
              name?: string;
              identification_number?: string;
              issue_date?: string;
              expiry_date?: string;
              issuing_country_code?: string;
              files?: {
                id?: string;
                reference_url?: string;
                content_type?: string;
                create_time?: string;
                size?: string;
              }[];
              links?: {
                href: string;
                rel: string;
                method?:
                  | "GET"
                  | "POST"
                  | "PUT"
                  | "DELETE"
                  | "HEAD"
                  | "CONNECT"
                  | "OPTIONS"
                  | "PATCH";
              }[];
            } & {
              type?:
                | "SOCIAL_SECURITY_NUMBER"
                | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                | "TAX_IDENTIFICATION_NUMBER"
                | "PASSPORT_NUMBER"
                | "PENSION_FUND_ID"
                | "MEDICAL_INSURANCE_ID"
                | "CNPJ"
                | "CPF"
                | "PAN";
            }[];
          } & {
            role?:
              | "CEO"
              | "CHAIRMAN"
              | "DIRECTOR"
              | "SECRETARY"
              | "TREASURER"
              | "TRUSTEE";
          }[];
          annual_sales_volume_range?: {
            minimum_amount?: { currency_code: string; value: string };
            maximum_amount?: { currency_code: string; value: string };
          };
          average_monthly_volume_range?: {
            minimum_amount?: { currency_code: string; value: string };
            maximum_amount?: { currency_code: string; value: string };
          };
          purpose_code?:
            | "P0104"
            | "P0301"
            | "P0801"
            | "P0802"
            | "P0803"
            | "P0805"
            | "P0806"
            | "P0902"
            | "P1004"
            | "P1005"
            | "P1006"
            | "P1007"
            | "P1008"
            | "P1009"[];
          business_description?: string;
        };
      } & {
        email?: string;
        preferred_language_code?: string;
        tracking_id?: string;
        partner_config_override?: {
          partner_logo_url?: string;
          return_url?: string;
          return_url_description?: string;
          action_renewal_url?: string;
          show_add_credit_card?: false | true;
        };
        financial_instruments?: {
          banks?: {
            nick_name?: string;
            account_number: string;
            account_type: "CHECKING" | "SAVINGS";
            currency_code?: string;
            identifiers?: {
              type?:
                | "BANK_CODE"
                | "BI_CODE"
                | "ROUTING_NUMBER_1"
                | "ROUTING_NUMBER_2"
                | "ROUTING_NUMBER_3"
                | "SWIFT_CODE"
                | "BRANCH_CODE"
                | "INTERMEDIARY_SWIFT_CODE"
                | "BBAN"
                | "BBAN_ENCRYPTED"
                | "BBAN_HMAC"
                | "AGGREGATOR_YODLEE";
              value?: string;
            }[];
            branch_location?: {
              address_line_1?: string;
              address_line_2?: string;
              address_line_3?: string;
              admin_area_4?: string;
              admin_area_3?: string;
              admin_area_2?: string;
              admin_area_1?: string;
              postal_code?: string;
              country_code: string;
              address_details?: {
                street_number?: string;
                street_name?: string;
                street_type?: string;
                delivery_service?: string;
                building_name?: string;
                sub_building?: string;
              };
            };
            mandate?: { accepted: false | true };
          }[];
        };
        operations?: {
          operation?:
            | "API_INTEGRATION"
            | "BANK_ADDITION"
            | "BILLING_AGREEMENT"
            | "CONTEXTUAL_MARKETING_CONSENT"
            | "SALESFORCE_REFERRAL";
          api_integration_preference?: {
            classic_api_integration?: {};
            rest_api_integration?: {
              integration_method?: "BRAINTREE" | "PAYPAL";
              integration_type?: "FIRST_PARTY" | "THIRD_PARTY";
              first_party_details?: {
                features:
                  | "BILLING_AGREEMENT"
                  | "PAYOUTS"
                  | "PAYMENT"
                  | "REFUND"
                  | "FUTURE_PAYMENT"
                  | "DIRECT_PAYMENT"
                  | "PARTNER_FEE"
                  | "DELAY_FUNDS_DISBURSEMENT"
                  | "READ_SELLER_DISPUTE"
                  | "UPDATE_SELLER_DISPUTE"
                  | "ADVANCED_TRANSACTIONS_SEARCH"
                  | "SWEEP_FUNDS_EXTERNAL_SINK"
                  | "ACCESS_MERCHANT_INFORMATION"
                  | "TRACKING_SHIPMENT_READWRITE"
                  | "INVOICE_READ_WRITE"
                  | "DISPUTE_READ_BUYER"
                  | "UPDATE_CUSTOMER_DISPUTES"
                  | "VAULT"[];
                seller_nonce: string;
              };
              third_party_details?: {
                features:
                  | "BILLING_AGREEMENT"
                  | "PAYOUTS"
                  | "PAYMENT"
                  | "REFUND"
                  | "FUTURE_PAYMENT"
                  | "DIRECT_PAYMENT"
                  | "PARTNER_FEE"
                  | "DELAY_FUNDS_DISBURSEMENT"
                  | "READ_SELLER_DISPUTE"
                  | "UPDATE_SELLER_DISPUTE"
                  | "ADVANCED_TRANSACTIONS_SEARCH"
                  | "SWEEP_FUNDS_EXTERNAL_SINK"
                  | "ACCESS_MERCHANT_INFORMATION"
                  | "TRACKING_SHIPMENT_READWRITE"
                  | "INVOICE_READ_WRITE"
                  | "DISPUTE_READ_BUYER"
                  | "UPDATE_CUSTOMER_DISPUTES"
                  | "VAULT"[];
              };
            };
          };
          billing_agreement?: {
            description?: string;
            billing_experience_preference?: {
              experience_id?: string;
              billing_context_set?: false | true;
            };
            merchant_custom_data?: string;
            approval_url?: string;
            ec_token?: string;
          };
        }[];
        products?:
          | "EXPRESS_CHECKOUT"
          | "PAYPAL_COMMERCE_PLATFORM_BUSINESS"
          | "PPPLUS"
          | "WEBSITE_PAYMENT_PRO"
          | "PAYMENT_METHODS"
          | "PPCP"
          | "ADVANCED_VAULTING"
          | "IZETTLE"[];
        capabilities?:
          | "PAYPAL_WALLET_VAULTING_ADVANCED"
          | "PAY_UPON_INVOICE"
          | "APPLE_PAY"[];
        outside_process_dependencies?: unknown[];
        legal_consents?: { type: "SHARE_DATA_CONSENT"; granted: false | true }[];
        payout_attributes?: {
          marketplace?: false | true;
          kyc_required?: false | true;
          country_transfer_method_currency_selection?: {
            country?: string;
            transfer_methods?: {
              transfer_method_type?:
                | "PAYPAL"
                | "BANK_ACCOUNT"
                | "VENMO"
                | "WIRE_ACCOUNT";
              currencies?: string[];
            }[];
          }[];
        };
      },
    ) {
      const token = await getToken(auth);
      const url = new URL(`https://api-m.paypal.com/v2/customer/partner-referrals`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "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

  • bun
    //native
    type Paypal = {
      token: string;
    };
    /**
     * Create partner referral
     * Creates a partner referral that is shared by the partner or API caller. The partner referral is used to onboard the seller, and contains the seller's personal, business, financial and operations.
     */
    export async function main(
      auth: Paypal,
      body: {
        individual_owners?: {
          id?: string;
          names?: {
            prefix?: string;
            given_name?: string;
            surname?: string;
            middle_name?: string;
            suffix?: string;
            full_name?: string;
          } & { type?: "LEGAL" }[];
          citizenship?: string;
          addresses?: {
            address_line_1?: string;
            address_line_2?: string;
            address_line_3?: string;
            admin_area_4?: string;
            admin_area_3?: string;
            admin_area_2?: string;
            admin_area_1?: string;
            postal_code?: string;
            country_code: string;
            address_details?: {
              street_number?: string;
              street_name?: string;
              street_type?: string;
              delivery_service?: string;
              building_name?: string;
              sub_building?: string;
            };
          } & { type?: "HOME"; primary?: false | true; inactive?: false | true }[];
          phones?: {
            country_code: string;
            national_number: string;
            extension_number?: string;
          } & {
            contact_name?: string;
            inactive?: false | true;
            primary?: false | true;
            primary_mobile?: false | true;
            type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
            tags?: "MOBILE" | "LANDLINE"[];
          }[];
          birth_details?: { date_of_birth: string };
          documents?: {
            id?: string;
            labels?: string[];
            name?: string;
            identification_number?: string;
            issue_date?: string;
            expiry_date?: string;
            issuing_country_code?: string;
            files?: {
              id?: string;
              reference_url?: string;
              content_type?: string;
              create_time?: string;
              size?: string;
            }[];
            links?: {
              href: string;
              rel: string;
              method?:
                | "GET"
                | "POST"
                | "PUT"
                | "DELETE"
                | "HEAD"
                | "CONNECT"
                | "OPTIONS"
                | "PATCH";
            }[];
          } & {
            type?:
              | "SOCIAL_SECURITY_NUMBER"
              | "EMPLOYMENT_IDENTIFICATION_NUMBER"
              | "TAX_IDENTIFICATION_NUMBER"
              | "PASSPORT_NUMBER"
              | "PENSION_FUND_ID"
              | "MEDICAL_INSURANCE_ID"
              | "CNPJ"
              | "CPF"
              | "PAN";
          }[];
        } & { type?: "PRIMARY" }[];
        business_entity?: {
          business_type?: {
            type?:
              | "ANY_OTHER_BUSINESS_ENTITY"
              | "ASSOCIATION"
              | "CORPORATION"
              | "GENERAL_PARTNERSHIP"
              | "GOVERNMENT"
              | "INDIVIDUAL"
              | "LIMITED_LIABILITY_PARTNERSHIP"
              | "LIMITED_LIABILITY_PROPRIETORS"
              | "LIMITED_LIABILITY_PRIVATE_CORPORATION"
              | "LIMITED_PARTNERSHIP"
              | "LIMITED_PARTNERSHIP_PRIVATE_CORPORATION"
              | "NONPROFIT"
              | "ONLY_BUY_OR_SEND_MONEY"
              | "OTHER_CORPORATE_BODY"
              | "PARTNERSHIP"
              | "PRIVATE_PARTNERSHIP"
              | "PROPRIETORSHIP"
              | "PROPRIETORSHIP_CRAFTSMAN"
              | "PROPRIETORY_COMPANY"
              | "PRIVATE_CORPORATION"
              | "PUBLIC_COMPANY"
              | "PUBLIC_CORPORATION"
              | "PUBLIC_PARTNERSHIP"
              | "REGISTERED_COOPERATIVE";
            subtype?:
              | "ASSO_TYPE_INCORPORATED"
              | "ASSO_TYPE_NON_INCORPORATED"
              | "GOVT_TYPE_ENTITY"
              | "GOVT_TYPE_EMANATION"
              | "GOVT_TYPE_ESTD_COMM"
              | "GOVT_TYPE_ESTD_FC"
              | "GOVT_TYPE_ESTD_ST_TR";
          };
          business_industry?: {
            category: string;
            mcc_code: string;
            subcategory: string;
          };
          business_incorporation?: {
            incorporation_country_code?: string;
            incorporation_date?: string;
            incorporation_province_code?: string;
          };
          names?: { business_name?: string } & {
            id?: string;
            type?: "DOING_BUSINESS_AS" | "LEGAL_NAME";
          }[];
          emails?: { type: "CUSTOMER_SERVICE"; email: string }[];
          website?: string;
          addresses?: {
            address_line_1?: string;
            address_line_2?: string;
            address_line_3?: string;
            admin_area_4?: string;
            admin_area_3?: string;
            admin_area_2?: string;
            admin_area_1?: string;
            postal_code?: string;
            country_code: string;
            address_details?: {
              street_number?: string;
              street_name?: string;
              street_type?: string;
              delivery_service?: string;
              building_name?: string;
              sub_building?: string;
            };
          } & { type?: "WORK"; primary?: false | true; inactive?: false | true }[];
          phones?: {
            country_code: string;
            national_number: string;
            extension_number?: string;
          } & {
            contact_name?: string;
            inactive?: false | true;
            primary?: false | true;
            type?: "CUSTOMER_SERVICE" | "BUSINESS";
            tags?: "MOBILE" | "LANDLINE"[];
          }[];
          documents?: {
            id?: string;
            labels?: string[];
            name?: string;
            identification_number?: string;
            issue_date?: string;
            expiry_date?: string;
            issuing_country_code?: string;
            files?: {
              id?: string;
              reference_url?: string;
              content_type?: string;
              create_time?: string;
              size?: string;
            }[];
            links?: {
              href: string;
              rel: string;
              method?:
                | "GET"
                | "POST"
                | "PUT"
                | "DELETE"
                | "HEAD"
                | "CONNECT"
                | "OPTIONS"
                | "PATCH";
            }[];
          } & {
            type?:
              | "SOCIAL_SECURITY_NUMBER"
              | "EMPLOYMENT_IDENTIFICATION_NUMBER"
              | "TAX_IDENTIFICATION_NUMBER"
              | "PASSPORT_NUMBER"
              | "PENSION_FUND_ID"
              | "MEDICAL_INSURANCE_ID"
              | "CNPJ"
              | "CPF"
              | "PAN";
          }[];
        } & {
          beneficial_owners?: {
            individual_beneficial_owners?: {
              id?: string;
              names?: {
                prefix?: string;
                given_name?: string;
                surname?: string;
                middle_name?: string;
                suffix?: string;
                full_name?: string;
              } & { type?: "LEGAL" }[];
              citizenship?: string;
              addresses?: {
                address_line_1?: string;
                address_line_2?: string;
                address_line_3?: string;
                admin_area_4?: string;
                admin_area_3?: string;
                admin_area_2?: string;
                admin_area_1?: string;
                postal_code?: string;
                country_code: string;
                address_details?: {
                  street_number?: string;
                  street_name?: string;
                  street_type?: string;
                  delivery_service?: string;
                  building_name?: string;
                  sub_building?: string;
                };
              } & {
                type?: "HOME";
                primary?: false | true;
                inactive?: false | true;
              }[];
              phones?: {
                country_code: string;
                national_number: string;
                extension_number?: string;
              } & {
                contact_name?: string;
                inactive?: false | true;
                primary?: false | true;
                primary_mobile?: false | true;
                type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
                tags?: "MOBILE" | "LANDLINE"[];
              }[];
              birth_details?: { date_of_birth: string };
              documents?: {
                id?: string;
                labels?: string[];
                name?: string;
                identification_number?: string;
                issue_date?: string;
                expiry_date?: string;
                issuing_country_code?: string;
                files?: {
                  id?: string;
                  reference_url?: string;
                  content_type?: string;
                  create_time?: string;
                  size?: string;
                }[];
                links?: {
                  href: string;
                  rel: string;
                  method?:
                    | "GET"
                    | "POST"
                    | "PUT"
                    | "DELETE"
                    | "HEAD"
                    | "CONNECT"
                    | "OPTIONS"
                    | "PATCH";
                }[];
              } & {
                type?:
                  | "SOCIAL_SECURITY_NUMBER"
                  | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                  | "TAX_IDENTIFICATION_NUMBER"
                  | "PASSPORT_NUMBER"
                  | "PENSION_FUND_ID"
                  | "MEDICAL_INSURANCE_ID"
                  | "CNPJ"
                  | "CPF"
                  | "PAN";
              }[];
            } & { percentage_of_ownership?: string }[];
            business_beneficial_owners?: {
              business_type?: {
                type?:
                  | "ANY_OTHER_BUSINESS_ENTITY"
                  | "ASSOCIATION"
                  | "CORPORATION"
                  | "GENERAL_PARTNERSHIP"
                  | "GOVERNMENT"
                  | "INDIVIDUAL"
                  | "LIMITED_LIABILITY_PARTNERSHIP"
                  | "LIMITED_LIABILITY_PROPRIETORS"
                  | "LIMITED_LIABILITY_PRIVATE_CORPORATION"
                  | "LIMITED_PARTNERSHIP"
                  | "LIMITED_PARTNERSHIP_PRIVATE_CORPORATION"
                  | "NONPROFIT"
                  | "ONLY_BUY_OR_SEND_MONEY"
                  | "OTHER_CORPORATE_BODY"
                  | "PARTNERSHIP"
                  | "PRIVATE_PARTNERSHIP"
                  | "PROPRIETORSHIP"
                  | "PROPRIETORSHIP_CRAFTSMAN"
                  | "PROPRIETORY_COMPANY"
                  | "PRIVATE_CORPORATION"
                  | "PUBLIC_COMPANY"
                  | "PUBLIC_CORPORATION"
                  | "PUBLIC_PARTNERSHIP"
                  | "REGISTERED_COOPERATIVE";
                subtype?:
                  | "ASSO_TYPE_INCORPORATED"
                  | "ASSO_TYPE_NON_INCORPORATED"
                  | "GOVT_TYPE_ENTITY"
                  | "GOVT_TYPE_EMANATION"
                  | "GOVT_TYPE_ESTD_COMM"
                  | "GOVT_TYPE_ESTD_FC"
                  | "GOVT_TYPE_ESTD_ST_TR";
              };
              business_industry?: {
                category: string;
                mcc_code: string;
                subcategory: string;
              };
              business_incorporation?: {
                incorporation_country_code?: string;
                incorporation_date?: string;
                incorporation_province_code?: string;
              };
              names?: { business_name?: string } & {
                id?: string;
                type?: "DOING_BUSINESS_AS" | "LEGAL_NAME";
              }[];
              emails?: { type: "CUSTOMER_SERVICE"; email: string }[];
              website?: string;
              addresses?: {
                address_line_1?: string;
                address_line_2?: string;
                address_line_3?: string;
                admin_area_4?: string;
                admin_area_3?: string;
                admin_area_2?: string;
                admin_area_1?: string;
                postal_code?: string;
                country_code: string;
                address_details?: {
                  street_number?: string;
                  street_name?: string;
                  street_type?: string;
                  delivery_service?: string;
                  building_name?: string;
                  sub_building?: string;
                };
              } & {
                type?: "WORK";
                primary?: false | true;
                inactive?: false | true;
              }[];
              phones?: {
                country_code: string;
                national_number: string;
                extension_number?: string;
              } & {
                contact_name?: string;
                inactive?: false | true;
                primary?: false | true;
                type?: "CUSTOMER_SERVICE" | "BUSINESS";
                tags?: "MOBILE" | "LANDLINE"[];
              }[];
              documents?: {
                id?: string;
                labels?: string[];
                name?: string;
                identification_number?: string;
                issue_date?: string;
                expiry_date?: string;
                issuing_country_code?: string;
                files?: {
                  id?: string;
                  reference_url?: string;
                  content_type?: string;
                  create_time?: string;
                  size?: string;
                }[];
                links?: {
                  href: string;
                  rel: string;
                  method?:
                    | "GET"
                    | "POST"
                    | "PUT"
                    | "DELETE"
                    | "HEAD"
                    | "CONNECT"
                    | "OPTIONS"
                    | "PATCH";
                }[];
              } & {
                type?:
                  | "SOCIAL_SECURITY_NUMBER"
                  | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                  | "TAX_IDENTIFICATION_NUMBER"
                  | "PASSPORT_NUMBER"
                  | "PENSION_FUND_ID"
                  | "MEDICAL_INSURANCE_ID"
                  | "CNPJ"
                  | "CPF"
                  | "PAN";
              }[];
            } & { percentage_of_ownership?: string }[];
          };
          office_bearers?: {
            id?: string;
            names?: {
              prefix?: string;
              given_name?: string;
              surname?: string;
              middle_name?: string;
              suffix?: string;
              full_name?: string;
            } & { type?: "LEGAL" }[];
            citizenship?: string;
            addresses?: {
              address_line_1?: string;
              address_line_2?: string;
              address_line_3?: string;
              admin_area_4?: string;
              admin_area_3?: string;
              admin_area_2?: string;
              admin_area_1?: string;
              postal_code?: string;
              country_code: string;
              address_details?: {
                street_number?: string;
                street_name?: string;
                street_type?: string;
                delivery_service?: string;
                building_name?: string;
                sub_building?: string;
              };
            } & {
              type?: "HOME";
              primary?: false | true;
              inactive?: false | true;
            }[];
            phones?: {
              country_code: string;
              national_number: string;
              extension_number?: string;
            } & {
              contact_name?: string;
              inactive?: false | true;
              primary?: false | true;
              primary_mobile?: false | true;
              type?: "HOME" | "FAX" | "MOBILE" | "OTHER" | "PAGER";
              tags?: "MOBILE" | "LANDLINE"[];
            }[];
            birth_details?: { date_of_birth: string };
            documents?: {
              id?: string;
              labels?: string[];
              name?: string;
              identification_number?: string;
              issue_date?: string;
              expiry_date?: string;
              issuing_country_code?: string;
              files?: {
                id?: string;
                reference_url?: string;
                content_type?: string;
                create_time?: string;
                size?: string;
              }[];
              links?: {
                href: string;
                rel: string;
                method?:
                  | "GET"
                  | "POST"
                  | "PUT"
                  | "DELETE"
                  | "HEAD"
                  | "CONNECT"
                  | "OPTIONS"
                  | "PATCH";
              }[];
            } & {
              type?:
                | "SOCIAL_SECURITY_NUMBER"
                | "EMPLOYMENT_IDENTIFICATION_NUMBER"
                | "TAX_IDENTIFICATION_NUMBER"
                | "PASSPORT_NUMBER"
                | "PENSION_FUND_ID"
                | "MEDICAL_INSURANCE_ID"
                | "CNPJ"
                | "CPF"
                | "PAN";
            }[];
          } & {
            role?:
              | "CEO"
              | "CHAIRMAN"
              | "DIRECTOR"
              | "SECRETARY"
              | "TREASURER"
              | "TRUSTEE";
          }[];
          annual_sales_volume_range?: {
            minimum_amount?: { currency_code: string; value: string };
            maximum_amount?: { currency_code: string; value: string };
          };
          average_monthly_volume_range?: {
            minimum_amount?: { currency_code: string; value: string };
            maximum_amount?: { currency_code: string; value: string };
          };
          purpose_code?:
            | "P0104"
            | "P0301"
            | "P0801"
            | "P0802"
            | "P0803"
            | "P0805"
            | "P0806"
            | "P0902"
            | "P1004"
            | "P1005"
            | "P1006"
            | "P1007"
            | "P1008"
            | "P1009"[];
          business_description?: string;
        };
      } & {
        email?: string;
        preferred_language_code?: string;
        tracking_id?: string;
        partner_config_override?: {
          partner_logo_url?: string;
          return_url?: string;
          return_url_description?: string;
          action_renewal_url?: string;
          show_add_credit_card?: false | true;
        };
        financial_instruments?: {
          banks?: {
            nick_name?: string;
            account_number: string;
            account_type: "CHECKING" | "SAVINGS";
            currency_code?: string;
            identifiers?: {
              type?:
                | "BANK_CODE"
                | "BI_CODE"
                | "ROUTING_NUMBER_1"
                | "ROUTING_NUMBER_2"
                | "ROUTING_NUMBER_3"
                | "SWIFT_CODE"
                | "BRANCH_CODE"
                | "INTERMEDIARY_SWIFT_CODE"
                | "BBAN"
                | "BBAN_ENCRYPTED"
                | "BBAN_HMAC"
                | "AGGREGATOR_YODLEE";
              value?: string;
            }[];
            branch_location?: {
              address_line_1?: string;
              address_line_2?: string;
              address_line_3?: string;
              admin_area_4?: string;
              admin_area_3?: string;
              admin_area_2?: string;
              admin_area_1?: string;
              postal_code?: string;
              country_code: string;
              address_details?: {
                street_number?: string;
                street_name?: string;
                street_type?: string;
                delivery_service?: string;
                building_name?: string;
                sub_building?: string;
              };
            };
            mandate?: { accepted: false | true };
          }[];
        };
        operations?: {
          operation?:
            | "API_INTEGRATION"
            | "BANK_ADDITION"
            | "BILLING_AGREEMENT"
            | "CONTEXTUAL_MARKETING_CONSENT"
            | "SALESFORCE_REFERRAL";
          api_integration_preference?: {
            classic_api_integration?: {};
            rest_api_integration?: {
              integration_method?: "BRAINTREE" | "PAYPAL";
              integration_type?: "FIRST_PARTY" | "THIRD_PARTY";
              first_party_details?: {
                features:
                  | "BILLING_AGREEMENT"
                  | "PAYOUTS"
                  | "PAYMENT"
                  | "REFUND"
                  | "FUTURE_PAYMENT"
                  | "DIRECT_PAYMENT"
                  | "PARTNER_FEE"
                  | "DELAY_FUNDS_DISBURSEMENT"
                  | "READ_SELLER_DISPUTE"
                  | "UPDATE_SELLER_DISPUTE"
                  | "ADVANCED_TRANSACTIONS_SEARCH"
                  | "SWEEP_FUNDS_EXTERNAL_SINK"
                  | "ACCESS_MERCHANT_INFORMATION"
                  | "TRACKING_SHIPMENT_READWRITE"
                  | "INVOICE_READ_WRITE"
                  | "DISPUTE_READ_BUYER"
                  | "UPDATE_CUSTOMER_DISPUTES"
                  | "VAULT"[];
                seller_nonce: string;
              };
              third_party_details?: {
                features:
                  | "BILLING_AGREEMENT"
                  | "PAYOUTS"
                  | "PAYMENT"
                  | "REFUND"
                  | "FUTURE_PAYMENT"
                  | "DIRECT_PAYMENT"
                  | "PARTNER_FEE"
                  | "DELAY_FUNDS_DISBURSEMENT"
                  | "READ_SELLER_DISPUTE"
                  | "UPDATE_SELLER_DISPUTE"
                  | "ADVANCED_TRANSACTIONS_SEARCH"
                  | "SWEEP_FUNDS_EXTERNAL_SINK"
                  | "ACCESS_MERCHANT_INFORMATION"
                  | "TRACKING_SHIPMENT_READWRITE"
                  | "INVOICE_READ_WRITE"
                  | "DISPUTE_READ_BUYER"
                  | "UPDATE_CUSTOMER_DISPUTES"
                  | "VAULT"[];
              };
            };
          };
          billing_agreement?: {
            description?: string;
            billing_experience_preference?: {
              experience_id?: string;
              billing_context_set?: false | true;
            };
            merchant_custom_data?: string;
            approval_url?: string;
            ec_token?: string;
          };
        }[];
        products?:
          | "EXPRESS_CHECKOUT"
          | "PAYPAL_COMMERCE_PLATFORM_BUSINESS"
          | "PPPLUS"
          | "WEBSITE_PAYMENT_PRO"
          | "PAYMENT_METHODS"
          | "PPCP"
          | "ADVANCED_VAULTING"
          | "IZETTLE"[];
        capabilities?:
          | "PAYPAL_WALLET_VAULTING_ADVANCED"
          | "PAY_UPON_INVOICE"
          | "APPLE_PAY"[];
        outside_process_dependencies?: unknown[];
        legal_consents?: { type: "SHARE_DATA_CONSENT"; granted: false | true }[];
        payout_attributes?: {
          marketplace?: false | true;
          kyc_required?: false | true;
          country_transfer_method_currency_selection?: {
            country?: string;
            transfer_methods?: {
              transfer_method_type?:
                | "PAYPAL"
                | "BANK_ACCOUNT"
                | "VENMO"
                | "WIRE_ACCOUNT";
              currencies?: string[];
            }[];
          }[];
        };
      },
    ) {
      const url = new URL(`https://api-m.paypal.com/v2/customer/partner-referrals`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "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