#mangell03_code

1 messages ¡ Page 1 of 1 (latest)

shell rainBOT
wary larkBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

shell rainBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1242186901658538108

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

keen wasp
#

Hello do you have an example ID of a payment intent that you saw this behavior on? From your error message it sounds like your intent is still in the default state of requires_payment_method so it sounds like you may have gotten a decline or may not have completed the hold before trying to capture the funds

shy bane
#

INTENT: {"id":"pi_3PIb0gEPuIFxKCqt0X3X9pwY","object":"payment_intent","amount":1000,"amount_capturable":0,"amount_details":{"tip":{}},"amount_received":0,"application":null,"application_fee_amount":null,"automatic_payment_methods":null,"canceled_at":null,"cancellation_reason":null,"capture_method":"manual","client_secret":"pi_3PIb0gEPuIFxKCqt0X3X9pwY_secret_LxuiTp7t07mb7PB3ETExaRW4g","confirmation_method":"automatic","created":1716229954,"currency":"usd","customer":null,"description":null,"invoice":null,"last_payment_error":null,"latest_charge":null,"livemode":false,"metadata":{},"next_action":null,"on_behalf_of":null,"payment_method":null,"payment_method_configuration_details":null,"payment_method_options":{"card_present":{"request_extended_authorization":false,"request_incremental_authorization_support":false}},"payment_method_types":["card_present"],"processing":null,"receipt_email":null,"review":null,"setup_future_usage":null,"shipping":null,"source":null,"statement_descriptor":null,"statement_descriptor_suffix":null,"status":"requires_payment_method","transfer_data":null,"transfer_group":null}

#

Here is the full code:

sync function createIntent () {

  const paymentIntent = await stripe.paymentIntents.create(
  {
    amount: 1000,
    currency: 'usd',
    payment_method_types: ['card_present'],
    capture_method: 'manual'
  }

)
  return (paymentIntent); 
}

// Define an async function to use await
async function main() {

var location;
var reader;
var processResult
  try {
    location = await retrieveLocation();
    console.log("LOCATION: " + JSON.stringify(location));
  } catch (error) {
    console.error("Error:", error);
  }
  var config = {simulated: true};


const readers = await stripe.terminal.readers.list({
  limit: 3,
});
 console.log("READERS: "+JSON.stringify(readers));

 reader = await stripe.terminal.readers.retrieve('tmr_FjdygQpwbvIHHQ');

 console.log("READER: "+JSON.stringify(reader));



    try {
    const token = await getToken();
    console.log("TOKEN2: " + JSON.stringify(token));
  } catch (error) {
    console.error("Error:", error);
  }

  try {
    intent = await createIntent();
    console.log("INTENT: " + JSON.stringify(intent));
  } catch (error) {
    console.error("Error:", error);
  }

  console.log("INTENT ID:"+intent.id);

  processResult = await stripe.terminal.readers.processPaymentIntent(reader.id,{payment_intent: intent.id});
  console.log("processResult: "+JSON.stringify(processResult));

 try {

      const capture = await stripe.paymentIntents.capture(intent.id);
          console.log("CAPTURE: " + JSON.stringify(capture));

    } catch (error) {
    console.error("Error:", error);
  
  }
  

};```
keen wasp
#

From what I can see that intent was sent to the terminal but it looks like the payment from the terminal never succeeded. Can you tell me about what you do on the terminal after you call processPaymentIntent and what you are seeing when you do it?

shy bane
#

I have a simulted terminal in my location. I am retrieving the terminal and passing its ID:

#

READER: {"id":"tmr_FjdygQpwbvIHHQ","object":"terminal.reader","action":{"failure_code":null,"failure_message":null,"process_payment_intent":{"payment_intent":"pi_3PIaz6EPuIFxKCqt08ATgWhA"},"status":"in_progress","type":"process_payment_intent"},"device_sw_version":"","device_type":"simulated_wisepos_e","ip_address":"0.0.0.0","label":"Sim 2","last_seen_at":1716229953845,"livemode":false,"location":"tml_FiuXCQpknBASRm","metadata":{},"serial_number":"5cfa7398-ff9d-4dc4-b8ad-ab51b0325194","status":"online"}

keen wasp
shy bane
#

Ok- now I see a status of "succeeded", but am still getting the same error on the capture:
READER2: {"id":"tmr_FjdygQpwbvIHHQ","object":"terminal.reader","action":{"failure_code":null,"failure_message":null,"process_payment_intent":{"payment_intent":"pi_3PIbZwEPuIFxKCqt1K7m6PMx"},"status":"succeeded","type":"process_payment_intent"},"device_sw_version":"","device_type":"simulated_wisepos_e","ip_address":"0.0.0.0","label":"Sim 2","last_seen_at":1716232181463,"livemode":false,"location":"tml_FiuXCQpknBASRm","metadata":{},"serial_number":"5cfa7398-ff9d-4dc4-b8ad-ab51b0325194","status":"online"}

keen wasp
#

It looks like you made the capture call 40 seconds before calling that present_payment_method call. The present payment method needs to happen first. That call is simulating someone paying with their card, you can't capture funds if the payment hasn't been made yet. Can you try capturing that intent's funds again?

shy bane
#

40 seconds? its all in one server.js. Here is the code I have:

  console.log("READER1: "+JSON.stringify(reader));

 reader = await stripe.testHelpers.terminal.readers.presentPaymentMethod(reader.id);

 console.log("READER2: "+JSON.stringify(reader));



    try {
    const token = await getToken();
    console.log("TOKEN2: " + JSON.stringify(token));
  } catch (error) {
    console.error("Error:", error);
  }

  try {
    intent = await createIntent();
    console.log("INTENT: " + JSON.stringify(intent));
  } catch (error) {
    console.error("Error:", error);
  }

  console.log("INTENT ID:"+intent.id);

  processResult = await stripe.terminal.readers.processPaymentIntent(reader.id,{payment_intent: intent.id});
  console.log("processResult: "+JSON.stringify(processResult));

 try {

      const capture = await stripe.paymentIntents.capture(intent.id);
          console.log("CAPTURE: " + JSON.stringify(capture));

    } catch (error) {
    console.error("Error:", error);
  
  }```
#

I am doing presentPaymentMethod before processPaymentIntent

keen wasp
#

So ideally a Terminal payment works like this:

  1. You send the payment intent to the terminal
  2. The customer taps or inserts their card, thus placing a hold on the funds
  3. You capture the funds later
    Your code currently does those steps in this order:
  4. Simulate the user tapping their card with presentPaymentMethod
  5. Send the intent to the Terminal
  6. Try to capture funds
shy bane
#

THAT WAS THE ONE LAST MISSING PIECE!! ITS WORKING!

Thank you so much. I knew I was close!

#

Time to order a real WisePOS! How much of the current code will need to be changed to get that to work?