Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Javascript - Return value from a callback javascript function and use it in next callback function

payresobj value is found good in the "function(instance, error, result)" scope,

Want to pass the same variable payresobj to "function(stage, expired)" , it is currently returning "undefined" , How can i pass the variable in that "function(stage, expired)" callback function to use it in the case switch scenarios.. Please Advice!

function checkout_card() {
  paysafe.checkout.setup("************************************", {
      amount: amt,
      currency: "USD",
      locale: "en_US",
      customer: {
        firstName: fname,
        lastName: lname,
        email: uemail,
        phone: "",
      },
      payout: false,
      payoutConfig: {
        maximumAmount: 999999
      },
      merchantRefNum: merchrefno,
      canEditAmount: false,
      environment: "TEST",
      singleUseCustomerToken: singletoken,
      displayPaymentMethods: ["card"],
      billingAddress: {
        street: staddress,
        city: bcity,
        zip: bzip,
        country: bcountry,
        state: bstate
      },
      simulator: "EXTERNAL",
      paymentMethodDetails: {
        card: {
          accountId: "********"
        }
      },
    },
    function(instance, error, result) {
      //console.log(error);
      if (error) {
        console.log(error);

      }

      if (result && result.paymentHandleToken) {
        payresobj = result
        return payresobj;

      } else {
        //alert(error.message);

      }
    },
    function(stage, expired) {
      console.log(stage);

      //console.log(instance)
      console.log(payresobj);
      switch (stage) {

        case "PAYMENT_HANDLE_NOT_CREATED": // Handle the scenario

          break;
        case "PAYMENT_HANDLE_CREATED": // Handle the scenario

        case "PAYMENT_HANDLE_REDIRECT": // Handle the scenario
          console.log("PAYMENT_HANDLE_REDIRECT");

          break;

        default: // Handle the scenario
          console.log("DEFAULT");

      }
    });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!