0

feeling dumb this morning. I try to select a value from a returned object but every time when I select the object I get undefined.

returned result

child {
  Description: 'This is a wallet',
  Owners: [ '62766708' ],
  Balance: { Currency: 'GBP', Amount: 0 },
  Currency: 'GBP',
  FundsType: 'DEFAULT',
  Id: '62766709',
  Tag: null,
  CreationDate: 1552916375 }

function

let resultToUpdate;
  if (userType == "natural") {
    resultToUpdate = await createNaturalUser(
      firstName,
      lastName,
      birthday,
      nationality,
      countryOfResidence,
      email
    );
    setTimeout(() => {
      console.log(resultToUpdate.child); // undefined
    }, 1000);
  }

As you can see I've tried even a setTimeout

EDIT. Here is createNaturalUser function which extends to createUserWallet. So child object from above is returned from second function

// ======================================================================
// CREATE NATURAL USER
// ======================================================================

export function createNaturalUser(
  firstName,
  lastName,
  birthday,
  nationality,
  countryOfResidence,
  email
) {
  var result = new Date(birthday).getTime().toString();
  var birthdayTimestamped = Number(result.slice(0, -3));
  var naturalUser = new mangoPay.models.UserNatural({
    FirstName: firstName, // First Name
    LastName: lastName, // Last Name
    Birthday: birthdayTimestamped, // timestamp
    Nationality: nationality, //
    CountryOfResidence: countryOfResidence, //
    Email: email // User email
  });

  return mangoPay.Users.create(naturalUser).then(function(response) {
    // Output the created user data to console
    return createUserWallet(response.Id);
  });
}

// ======================================================================
// CREATE USER WALLET
// ======================================================================

export function createUserWallet(owner) {
  var userWallet = new mangoPay.models.Wallet({
    Owners: [owner],
    Description: "This is a wallet",
    Currency: "GBP"
  });

  return mangoPay.Wallets.create(userWallet).then(function(response) {
    // console.log(response);
    return response;
  });
}
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Markus Hayner
  • 2,869
  • 2
  • 28
  • 60

0 Answers0