hosted-fields/public/cards.js
// complete checkout by submitting the card form and capturing payment
complete checkout by submitting the card form and capturing payment
complete checkout by submitting the card form and capturing payment
async function checkout(cardFields) {
  const { orderId } = await cardFields.submit({
    cardholderName: cardholderName.value,
    billingAddress: {
      postalCode: postalCode.value,
      countryCodeAlpha2: countryCode.value,
    },
  });
  const orderData = await api.captureOrder(orderId);
  const errorDetail = Array.isArray(orderData.details) && orderData.details[0];
  if (errorDetail && errorDetail.issue === "INSTRUMENT_DECLINED") {
    return alert("Please try a different funding source.");
  }
  if (errorDetail) {
    let msg = "Sorry, your transaction could not be processed.";
    if (errorDetail.description) {
      msg += "\n\n" + errorDetail.description;
    }
    if (orderData.debug_id) {
      msg += " (" + orderData.debug_id + ")";
    }
    return alert(msg); 
  }
  window.location = "/?success";
}
async function checkout ( cardFields ) { const { orderId } = await cardFields . submit ( { cardholderName : cardholderName . value , billingAddress : { postalCode : postalCode . value , countryCodeAlpha2 : countryCode . value , } , } ) ; const orderData = await api . captureOrder ( orderId ) ; const errorDetail = Array . isArray ( orderData . details ) && orderData . details [ 0 ] ; if ( errorDetail && errorDetail . issue === "INSTRUMENT_DECLINED" ) { return alert ( "Please try a different funding source." ) ; } if ( errorDetail ) { let msg = "Sorry, your transaction could not be processed." ; if ( errorDetail . description ) { msg += "\n\n" + errorDetail . description ; } if ( orderData . debug_id ) { msg += " (" + orderData . debug_id + ")" ; } return alert ( msg ) ; } window . location = "/?success" ; }
complete checkout by submitting the card form and capturing payment
complete checkout by submitting the card form and capturing payment
// submit completes the process of creating an order // once the order has all the neccessary info we can call capture // recoverable errors // See: https://developer.paypal.com/docs/checkout/standard/customize/handle-funding-failures/ // unrecoverable errors // Show a failure message // show a success message or redirect