#0Bietnua-ios-check-default-pm
1 messages · Page 1 of 1 (latest)
Hello 👋
Could you clarify the use-case for me here? 🙂
Typically you'd want to check this on your server-side
Right now I am able to set default payment method by calling one of api on our backend
So is there any way from sdk
I can know the current user already have default payment method
I need it to remove some warning on UI
So not sure I can get that information directly from sdk or I can’t
hmm let me check
Thanks
As far as I can tell (i haven't personally tested this yet)
but you can use STPCustomerContext to retrieve the customer and check if they have a default PM
https://stripe.dev/stripe-ios/docs/Classes/STPCustomerContext.html
I can get customer from customer context but I don’t see any property to determine about default payment method
I can see defaultSource
But not sure that is default payment method
it may or may not be depending on what you're using as a payment method
https://stripe.com/docs/api/customers/update#update_customer-default_source
Oh no! sorry for the confusion. I was just pointing to the field description.
Default source may not be the default if you use PaymentMethod API.
You'd also want to check invoiceSettings > default_payment_method
I can see it but I don’t see invoice setting in response
https://api.stripe.com/v1/customers/cus_KHmljPMPHNr7DN?
{
"id": "cus_KHmljPMPHNr7DN",
"object": "customer",
"created": 1632485267,
"default_source": null,
"default_source_type": null,
"description": null,
"email": "abc@abc.com",
"livemode": false,
"shipping": null
}
ah okay
Let me dig deeper
I can get customer info
customerContext.retrieveCustomer { customer, eror in
customer?.allResponseFields
}
but seem there is not much information and also don't see anything relates to default payment method
and the response that you're seeing is the same as what you pasted above?
same information
Optional<Dictionary<AnyHashable, Any>>
▿ some : 9 elements
▿ 0 : 2 elements
▿ key : AnyHashable("email")
- value : "email"
- value : abc@abc.com
▿ 1 : 2 elements
▿ key : AnyHashable("livemode")
- value : "livemode"
- value : 0
▿ 2 : 2 elements
▿ key : AnyHashable("default_source")
- value : "default_source"
- value : <null>
▿ 3 : 2 elements
▿ key : AnyHashable("shipping")
- value : "shipping"
- value : <null>
▿ 4 : 2 elements
▿ key : AnyHashable("description")
- value : "description"
- value : <null>
▿ 5 : 2 elements
▿ key : AnyHashable("id")
- value : "id"
- value : cus_KHmljPMPHNr7DN
▿ 6 : 2 elements
▿ key : AnyHashable("default_source_type")
- value : "default_source_type"
- value : <null>
▿ 7 : 2 elements
▿ key : AnyHashable("created")
- value : "created"
- value : 1632485267
▿ 8 : 2 elements
▿ key : AnyHashable("object")
- value : "object"
- value : customer
(lldb)
I can see list of payment method
but no thing relate to default payment method
the list is use for STPPaymentOptionsViewController
same data
Ah okay! Was worth a try.
Let me reach out to a colleague as I don't have the sandbox setup yet to test this out.
Appreciate your patience though 🙂 thank you
{
"object": "list",
"data": [
{
"id": "pm_1Kiy7yFl4EumnGYfaFP5hYA5",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": "95678 ",
"state": null
},
"email": null,
"name": null,
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "US",
"exp_month": 11,
"exp_year": 2022,
"fingerprint": "IahTe3KX8yvOLDcq",
"funding": "credit",
"generated_from": null,
"last4": "1111",
"networks": {
"available": [
"visa"
],
"preferred": null
},
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1648633667,
"customer": "cus_KHmljPMPHNr7DN",
"livemode": false,
"type": "card"
}
no worry, just wanna check I can get from SDK or not
if not I will ask backend guy to help me
I've looked through the SDK docs and not finding a reference to the default payment method anywhere so it is highly likely that its not supported. I've reached out to my colleagues to confirm this
okay. Thanks for that.
so we can't get it from SDK
let me ask backend guy to help me
Thanks for your help
No worries. We're still waiting on confirmation on what I mentioned above and checking if there are any workarounds available
I have one more question
when cilck done
sdk doesn't return to this list
I saw sdk return paymentOptionsViewControllerDidFinish immediately
Is there any way I can go back the list after add a new card?
👋 I'm hopping in since @glass pine had to head out
For your original question about getting the invoice_settings.default_payment_method , there isn't a way to get this from STPCustomrContext. The simples option would be to retrieve the Customer from your backend and grab it from there
Still looking into the answer for your other question 👍
When you click "Done" what screen do you get directed to?
it return to paymentOptionsViewControllerDidFinish
in paymentOptionsViewControllerDidFinish, I will close the list
is this current design?
I believe this is by design - the thought is that if you're adding a new card, that's the card that you want to use to complete the payment. You'd only need to see the full list of payment methods if you hadn't selected a card to use yet
ok, got it. Thank you