#amfpaulo_terminal-subscription

1 messages ยท Page 1 of 1 (latest)

radiant hearthBOT
#

๐Ÿ‘‹ 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/1260709743866023988

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

sharp verge
#

amfpaulo_terminal-subscription

#

@paper onyx We don't support Subscriptions for Terminal payments today. The best option is to collect the first payment as a one-off payment with Terminal and then start a Subscription with a trial or billing_cycle_anchor set to their future/next payment date.

#

Also Terminal is not for recurring payments. So when you say the Update Customer default_payment_method failed you likely passed the wrong PaymentMethod id. I assume you passed the pm_123 for the type: 'card_present' PaymentMethod which is incorrect.
What you want is to use the generated card that is a separate PaymentMethod with type: 'card'

paper onyx
#

where can I find more info on the docs or could you give me a high level guidance ?

sharp verge
#

I wish we had good docs for this, we don't, it's a huge mess.
So I think it depends which part of my answer you are asking about

paper onyx
#

ok, for the Payment method, after seting up the intent , I use this method from react native SDK to retrieve the payment method Id from the setupIntent:
const { setupIntent, error } = await collectSetupIntentPaymentMethod({
setupIntent: si,
customerConsentCollected: true,
enableCustomerCancellation: enableCustomerCancellation,
});

#

after that I call my backend to create the subscription:

await api.createSubscription({
customerId: 'cus_xxx',
priceId: 'price_xxx',
paymentMethodId: setupIntent.paymentMethodId,
});

sharp verge
#

yeah that's the wrong PaymentMethod id

paper onyx
#

how can I get the correct one ?

#

I think I can solve my problem If I can get the "generated card"

paper onyx
#

cool, I think I can progress a bit more with this information

#

Thank you. I appreciate your help

sharp verge
#

sure thing! You can test this in a few minutes so let me know if you get stuck. Note: all of this is server-side you can't do this client-side in the SDK

paper onyx
#

Thank you, Ya, I know, I am doing server side

#

It gave me the same error, also method returned to me the same id, this is my code

#

this si my create subscription that now, receives a intentId and find the correct generated card:

[HttpPost("create-subscription")]
public IActionResult CreateSubscription(SubscriptionRequest request)
{

    var opt = new SetupIntentGetOptions
    {
        Expand = new List<string> { "latest_attempt" },
    };
    var srv = new SetupIntentService();
    var i = srv.Get(request.SetupIntentId, opt);

    var paymentMethodId = i.PaymentMethodId;


    UpdateDeaultPayment(request.CustomerId, paymentMethodId);

    var options = new SubscriptionCreateOptions
    {
        Customer = request.CustomerId,
        Items = new List<SubscriptionItemOptions>
                    {
                        new SubscriptionItemOptions { Price = request.PriceId }
                    },
        DefaultPaymentMethod = paymentMethodId,
    };

    var service = new SubscriptionService();
    Subscription subscription = service.Create(options);

    return Ok(subscription);
}
sharp verge
#

yeah you didn't do what's in the doc I shared at all. You did ``` var srv = new SetupIntentService();
var i = srv.Get(request.SetupIntentId, opt);

    var paymentMethodId = i.PaymentMethodId;``` which is the `pm_123` for the `type: 'card_present'` here
#

This is the part of the doc that is crucial. I see you expanded but you never looked at the result

paper onyx
#

You are correct, I just rush, because was looking simple... Ok, I find it the correct property

#

lets see now

sharp verge
#

yeah it's so hidden and deep ๐Ÿ˜ฆ

paper onyx
#

I think I still doing something wrong, I find out the property i.LatestAttempt which I access the PaymentMethodId from the LatestAttempt, it returns to me the same card_present id

sharp verge
#

yes because you are still going way too fast I'm sorry

#

i.LatestAttempt.PaymentMethodDetails.CardPresent.GeneratedCard this is what you want

paper onyx
#

OMG

#

this is insane, anyways, GenerateCard as almost all objects was null, however like the norm, GeneratedCardId property was populated. Moreover WORKED !!!

#

You save the day, thank you.

#

I am thinking to contribute with . NET sample for the community after a finish this

#

thank you again

sharp verge
#

yeah GeneratedCard is for the full object if you expand it, if it's just an id it's null and you use GeneratedCardId

paper onyx
#

thank you again

sharp verge
#

happy to help!

paper onyx
#

last question, there is a quick way to check if the customer already has a default payment_method / card set ?

sharp verge
paper onyx
#

Cool, thank you man ! Have a great day