#lordstar7_code

1 messages ¡ Page 1 of 1 (latest)

tender crownBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1256070620958167111

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

sinful totemBOT
#

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.

umbral orbit
#

You can always update the PaymentIntent to the Customer. But keep in mind that will only marks the connection between PI <> Customer. If you want the Customer to have the Payment Method saved, you will need additional steps

hallow jewel
#

it has the right payment method so that should be ok... I just need to associate the customer?

stripe payment_intents update pi_3PQtzEGEfs7cZv8K1TkA4udJ --customer="cus_QKAD9KD2SUxHfI"
#

awesome, thanks

#

that worked

#

quick question

#

why does Jose have two transactions?

#

but when I go in there, there is only one?

umbral orbit
#

it has the right payment method.
But that PaymentMethod still not belongs to the Customer. You will need to

  1. Attach t he PM to the Customer
  2. Set the PM as the Customer's invoice_settings.default_payment_method
    So next time you charge the Customer it can use that PaymentMethod
hallow jewel
#

ok, will associate the PM as the customer

#
stripe customers update cus_QKAD9KD2SUxHfI -d "invoice_settings[default_payment_method]=pm_1PQu0xGEfs7cZv8KCgMHoGNh"
#
{
  "error": {
    "message": "The customer does not have a payment method with the ID pm_1PQu0xGEfs7cZv8KCgMHoGNh. The payment method must be attached to the customer.",
    "param": "payment_method",
    "request_log_url": "https://dashboard.stripe.com/logs/req_eOkN8zp5hkJp8H?t=1719543034",
    "type": "invalid_request_error"
  }
}
umbral orbit
#

Yes you need to call the Attach Payment Method first

hallow jewel
#

I see

#
stripe payment_methods attach pm_1PQu0xGEfs7cZv8KCgMHoGNh --customer="cus_QKAD9KD2SUxHfI"
{
  "error": {
    "message": "This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.",
    "request_log_url": "https://dashboard.stripe.com/logs/req_ynnlOd6a3zJRGo?t=1719544061",
    "type": "invalid_request_error"
  }
}
umbral orbit
#

Oh that's right! Sorry yes I overlook this case. It's because the Paymentmethod was used previously without setup_future_usage

#

In short: You can create and confirm a PI, then later create a Customer and attach the previously used PM to it only if the first PI was created with setup_future_usage

#

Example flow (in Ruby)

pi2 = Stripe::PaymentIntent.create({
  amount: 2000,
  currency: 'jpy',
  setup_future_usage: 'off_session',
  payment_method_types: ['card'],
})
cpi2 = Stripe::PaymentIntent.confirm(
  pi2.id,
  {
    payment_method: 'pm_card_visa'
  },
)
p cpi2.id
p cpi2.payment_method

cus2 = Stripe::Customer.create({})
Stripe::PaymentMethod.attach(
  cpi2.payment_method,
  {customer: cus2.id},
)
pm2 = Stripe::PaymentMethod.retrieve(cpi2.payment_method)
p pm2
#

note the setup_future_usage: 'off_session'

hallow jewel
#
Future<Map<String, dynamic>?> createPaymentIntent({
    required double amount,
    String? customerId,
  }) async {
    Map<String, dynamic> map = {};

    map['amount'] = calculateAmount(amount);
    map['currency'] = 'USD';
    map['payment_method_types[]'] = 'card';
    map['capture_method'] = 'manual';
    if (customerId != null) map['customer'] = customerId;
    debugPrint("_environment?.stripeSecretkey ::${_environment?.stripeSecretkey}");
    try {
      var response = await http.post(
        Uri.parse('https://api.stripe.com/v1/payment_intents'),
        headers: {
          'Authorization': 'Bearer ${_environment?.stripeSecretkey}',
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: map,
      );
      // log('Payment Intent Body->>> ${response.body.toString()}');
      return jsonDecode(response.body);
    } on StripeException catch (ex) {
      // SnackBarAlerts.warningAlert(message: "Error Occurred while Paying.");
      // log('Inside Intent Catch Statement: ${ex.toString()}');
      return null;
    }
  }
#

so in my flutter code, I should simply add the

setup_future_usage: 'off_session',
#

or

map['setup_future_usage'] = 'on_session';
#

ok, I'll change the code and confirm that this is on

#
stripe payment_methods retrieve pm_1PQu0xGEfs7cZv8KCgMHoGNh

results

{
  "id": "pm_1PQu0xGEfs7cZv8KCgMHoGNh",
  "object": "payment_method",
  "allow_redisplay": "unspecified",
  "billing_details": {
    "address": {
      "city": null,
      "country": "US",
      "line1": null,
      "line2": null,
      "postal_code": "80134",
      "state": null
    },
    "email": null,
    "name": null,
    "phone": null
  },
  "card": {
    "brand": "amex",
    "checks": {
      "address_line1_check": null,
      "address_postal_code_check": "pass",
      "cvc_check": "pass"
    },
    "country": "US",
    "display_brand": "american_express",
    "exp_month": 1,
    "exp_year": 2026,
    "fingerprint": "X9bQGPpDpxAcWYnp",
    "funding": "credit",
    "generated_from": null,
    "last4": "3009",
    "networks": {
      "available": [
        "amex"
      ],
      "preferred": null
    },
    "three_d_secure_usage": {
      "supported": true
    },
    "wallet": null
  },
  "created": 1718209631,
  "customer": null,
  "livemode": true,
  "metadata": {},
  "type": "card"
}
#

this is the payment method in question, I don't see the setup_future_usage

umbral orbit
#

It's on the PaymentIntent object

#

setup_future_usage is null here

hallow jewel
#

oh, checking now

#

so instead of null it should be off_session?

#

what is the different between off_session & on_session?

umbral orbit
#

It's about next time when you charge your Customer. If you anticipate they are offline -> use off_session

#

ie. you Charge them on the fly, on your server

hallow jewel
#

so going back to this...

#

how do I rectify this?

#

it should say $210 for Jose, and $0 for guest

umbral orbit
#

Can you open Joe 2 transactions? What is his customer id?

hallow jewel
umbral orbit
#

Can you paste here the Customer Id? cus_xxx

hallow jewel
#

cus_QKAD9KD2SUxHfI

umbral orbit
hallow jewel
umbral orbit
#

I believe that's the group of the Guest Customer we detected using the same card info

hallow jewel
#

how do I remove it from the guest customer?

#

the guest customer was jose

umbral orbit
#

Do you mean you want the Customer only display $210?

hallow jewel
#

yes

#

and I want the guest to not display anything

umbral orbit
#

Um sorry it's not possible nowsaday.

#

You could write to Support to double check