Edits history of script submission #12741 for ' Create web experience profile (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 web experience profile
     * Creates a web experience profile. In the JSON request body, specify the profile name and details.
     */
    export async function main(
      auth: Paypal,
      PayPal_Request_Id: string,
      body: {
        id?: string;
        name: string;
        temporary?: false | true;
        flow_config?: {
          landing_page_type?: "login" | "billing";
          bank_txn_pending_url?: string;
          user_action?: "COMMIT";
          return_uri_http_method?: "GET" | "POST";
        };
        input_fields?: { no_shipping?: number; address_override?: number };
        presentation?: {
          brand_name?: string;
          logo_image?: string;
          locale_code?: string;
        };
      },
    ) {
      const token = await getToken(auth);
      const url = new URL(
        `https://api-m.paypal.com/v1/payment-experience/web-profiles`,
      );
    
      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

  • bun
    //native
    type Paypal = {
      token: string;
    };
    /**
     * Create web experience profile
     * Creates a web experience profile. In the JSON request body, specify the profile name and details.
     */
    export async function main(
      auth: Paypal,
      PayPal_Request_Id: string,
      body: {
        id?: string;
        name: string;
        temporary?: false | true;
        flow_config?: {
          landing_page_type?: "login" | "billing";
          bank_txn_pending_url?: string;
          user_action?: "COMMIT";
          return_uri_http_method?: "GET" | "POST";
        };
        input_fields?: { no_shipping?: number; address_override?: number };
        presentation?: {
          brand_name?: string;
          logo_image?: string;
          locale_code?: string;
        };
      },
    ) {
      const url = new URL(
        `https://api-m.paypal.com/v1/payment-experience/web-profiles`,
      );
    
      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