question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello,

I’m trying to understand how functions can replace my current backend (ruby app on Heroku) that is set up and working for iOS payments.

From what I’ve done so far, it was simple to create customers and charge them by writing to the RTDB. However, I’m not sure how to retrieve the customer’s sources and populate the customer’s existing cards into the STPPaymentMethodsViewController.

For example, if the customer previously used two cards, STPPaymentMethodsViewController would show two sources and the customer would be able to choose one.

Would I have to set up a custom checkout process that:

  1. Reads in the user’s tokens from /stripe_customers/{userId}/sources/{pushId}/token
  2. Show them in a user-readable format in my app
  3. Based on the user’s selected card, tell Stripe to update the customer’s default source,
  4. And finally charge the customer by writing to the RTDB

I feel like I’m not thinking through this properly and that there must be a better way, any help would be greatly appreciated, thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jitaekcommented, Apr 28, 2017

In my retrieveCustomer method in the STPBackendAPIAdapter subclass, I have something like this. It’s still a work in progress but this is working so far for me.

    let userStripeRef = FIREBASE_REF.child("stripe_customers").child(userID)
    userStripeRef.observeSingleEvent(of: .value, with: { snapshot in
        
        // get the user's stripeID
        guard let stripeDict = snapshot.value as? [String:AnyObject], let customerID = stripeDict["customerID"] as? String else { return }

        // get the user's list of sources
        if let sourcesDict = stripeDict["sources"] as? [String:[String:AnyObject]] {
            
            // attach each existing source to the customer
            for (_, source) in sourcesDict {

                if let id = source["id"] as? String, let brand = source["brand"] as? String, let last4 = source["last4"] as? String, let expMonth = source["exp_month"] as? UInt, let expYear = source["exp_year"] as? UInt, let funding = source["funding"] as? String {
                    print("ADDING SOURCE")
                    let card = STPCard(id: id, brand: .visa, last4: last4, expMonth: expMonth, expYear: expYear, funding: .credit)
                    self.sources.append(card)
                    
                }
            }
        }            
        let customer = STPCustomer(stripeID: customerID, defaultSource: self.sources.first, sources: self.sources)
        completion(customer, nil)
        return
    })
0reactions
jpsanabriacommented, Apr 28, 2017

@jitaek do you have any front end Swift code that you would be willing to share. I’ve just setup the Cloud Functions and trying to figure out the basics of STPPaymentContext

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting started with Sources in the iOS SDK - Stripe
Learn how to use Sources in your iOS application. This guide assumes you've already installed and configured the Stripe iOS SDK and are...
Read more >
Set up your integration | Stripe Documentation
The Stripe Terminal iOS SDK is compatible with apps supporting iOS 10 and above, and can be installed with CocoaPods or Swift Package...
Read more >
Stripe iOS SDK - GitHub
The Stripe iOS SDK makes it quick and easy to build an excellent payment experience in your iOS app. We provide powerful and...
Read more >
Stripe Dashboard on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about Stripe Dashboard. Download Stripe Dashboard and enjoy it on your iPhone, iPad, ......
Read more >
Stripe iOS SDKs 23.3.1 Reference
Stripe iOS SDKs 23.3.1. Stripe. Accept online payments using Stripe. StripePayments. Bindings for the Stripe Payments API. StripePaymentsUI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found