Stripe integration with iOS: Saving and referencing saved cards - swift

I'm trying to make an app that sells a service, for which users pay based on the amount of time they've used it for, so I don't have a physical shipping address involved.
I want to be able to allow my users to save and then reference saved cards in future transactions. I know the way Stripe tracks a specific customer is through a customer_id, but I'm not sure how to attach a card to a specific customer_id and then reference it in future.
Also, I'm a little confused on the use of ephemeral_keys. Some Stripe tutorials talk about needing these on the server side, and some don't mention them at all, and that leaves me very confused.
This one talks about ephemeral_keys while creating a paymentIntent: https://stripe.com/docs/mobile/ios/basic#
And this one doesn't: https://stripe.com/docs/payments/integration-builder
Any help would be greatly appreciated! Please let me know if you need any more information from me.
PS: If you could also point me to some of the relevant View Controllers Stripe uses to save new cards and display saved cards, I'd be more than grateful!

The flow on https://stripe.com/docs/mobile/ios/basic includes the Customer for your payment context, which will cause the created PaymentMethod to be attached to that Customer. You can verify this after the initial payment by retrieving the PaymentMethod on your backend with your secret key and checking its customer field [0].
If you have a PaymentMethod and want to attach it to a Customer, you'd use the API on the backend [1].
You can retrieve a list of the Customer's existing PaymentMethods via the API [2] on the backed as well (again, with your secret key). Then you can pass a list of their id's and some identifying feature (last 4 digits, as an example) to your app in order to display and let the customer select the one they want to use. Then you take that PaymentMethod's 'id' and use it to create the new payment.
Ephemeral keys are usually only used with the iOS (or Android) SDK's, so when you're using the backend of your integration (i.e. the part that is running on a server somewhere and not distributed with your app) you generally don't need to worry about them.
[0] https://stripe.com/docs/api/payment_methods/retrieve
[1] https://stripe.com/docs/api/payment_methods/attach
[2] https://stripe.com/docs/api/payment_methods/list

Related

Google analytics and different domain tracking

I asked this question directly to the Google Analytics community with absolutely no answer.
The question is as follow:
I have a AI based site, which give a customer a specific aid to select the right product he/she want to buy. The front ed application is React/js based.
My site is usually a small icon on a merchant site, and the user, while he/she is navigating the merchant site, can decide to recall clicking on a specific icon.
Then my site opens and help the user to select the right product(s) belonging to the merchant site. The product are choosen and then clicked to be added to the merchant cart.
Of course, there is a written agreement between the merchant and I to be signed, and some changes to the merchant site to incorporate my clickable icon: I'd like to pass a piece of code to the merchant including the icon and all the code needed to implement this kind of application.
So, given that the merchant call my site passing a specific transaction related token and the customer info (if any) when the user click on my icon, how can I:
directly add one or more items into the merchant cart
track the action made by the user after he/she leave me site and return to the merchant one to conclude the journey with a payment, so I can later invoice the merchant for the right commission
track if the user remove some (or all the) item from the cart, so I have less to nothing commissions to invoice.
I tried to follow the instruction given by google, but they are a mess, and I wasn't able to reach any conclusion.
Any help will be really appreciated.
Adding items to the merchant's cart is possible using some live API that the client would extend, but the easiest way to do it would be just using the window.postMessage(). So, I would suggest having your button implemented as a simple iframe. That will make it possible for you to send messages to the parent page from that button. The parent page, however, has to be ready to listen to those messages and add to cart whatever ids you specify. So the client devs will have to do some implementation for this to work.
Well, no, this is a bit too much to ask for. You can ask the merchant to share that data with you so that you could improve your algos (tune them for the client) and, therefore, improve the merchant's conversion rates (which is a win-win scenario), but the merchant would have to actively either implement parallel tracking to your instance of analytics (install your pixel, if you're willing to develop one), or share their own data with you.
That's what a lot of very similar services do. Let's say, Facebook. Facebook sells traffic. When you buy traffic, you generally don't want to pay for irrelevant/badly converting tracking, so you're implementing so-called facebook pixel. Facebook doesn't do this implementation. Client's developers/implementation experts implement it and trigger various events through it, making it send signals to the FB endoint, indicating which client this is from, for which campaign, what the action is page load, purchase, add to cart... Just take a quick glance at FB documentation: https://www.facebook.com/business/help/402791146561655?id=1205376682832142
Facebook is just an example. There are many-many services that do similar pixels. It may be not about selling traffic, it may be about adjusting site look and feel based on AI, or generating discounts and customizing conversion funnels, or even simpler stuff like feedback chat performance and suggestions modules. All these and more exist as third parties and pretty much all of the established ones use pixels for tracking.
If you don't want to spend time at the moment to make your own tracking logic, then implementing a parallel GA tracking will be a pain for you (for your clients, actually). Instead, it would be easier to enrich their data with your products. Let's say, have them implement a product-level custom dimension that would "paint" products added to cart by you and share the data with you.
Note that a client who goes for it must be a very loyal client since analytics data is normally treated as sensitive and is not readily shared with third parties, not mentioning the implementation of a custom dimension (or the using the expensive product parameters) just for a third party to count their conversions. Yes, it has to be a good friend that allows this.
Finally, you could ask them installing your GTM instance or giving you access to theirs, but that would effectively give you the power to execute arbitrary code on any of their page. I would never give a third party that power.
Tl;Dr: I would suggest making your own very simple pixel. Even though it sounds now like a lot of work, it will worth it if the project itself has real potential to be useful for ecommerce.
Exactly the same as 2.

PayPal checkout: Don't allow creation of orders/subscriptions with only Client ID

I'm working on integrating PayPal Subscriptions into my web app. I create the subscriptions server-side, but it's trivial for anyone to create a subscription, since all PayPal requires is the public Client ID. This is intended to allow (mostly) server less transactions, but in my case it just feels like leaving part of my app exposed.
Is there any way to disable this?
Continue to use the clientId+secret that you have on the server side (or, create a new pair and deactivate your current pair, if you are paranoid)
Then, create a separate permissionless REST app for use from your buttons. Make sure it corresponds to the same sandbox account if testing in sandbox, and give it the name "no permissions" for clarity. In the app features section, uncheck everything.
This new clientid will not be able to create orders or subscriptions, but can be used to present the buttons and approve ones that were created server-side.

Stripe iOS integration server side code

I have been playing around with the Stripe SDK and API and I am a little confused. I have a very simple use case. I want to use the built in STPAddCardViewController and STPAddCardViewControllerDelegate to save card information that a user puts in. We also need to charge the card based on the credit card the user created. We have a unique identifier for each user when they create an account and any user that has access to our app does need to create an account. What is the best way to do this?
We also aren’t able to get the card information (STPCardParams) that a user selects from the STPAddCardViewControllerDelegate. How would we do that?
The part that I am having the most trouble with is the server side piece. I know Stripe gives example code for this but I haven’t been able to get it to work for us. We are using a backend as a service for our app so don’t use code to create our server. Is there any simple code that we can deploy that allows us to pass the card information, our Stripe API key, a charge amount, and a currency to a server (on heroku for example), and just have that server charge the card for us? I don’t think this is that hard to do and it seems like it can be pretty cookie cutter for everyone who is using stripe. If this is the case, does anybody have the code for this? Is it possible to use stripe without server side code?

Is there a way to use Shopify MetaFields to tag customers with data?

I've been trying to find a way to store a piece of data relative to a customer in my store. Ideally I was hoping to be able to create a Metafield that would store a single numerical value and be retrievable by the customer's id or email.
Any thoughts or suggestions would be really appreciated. Ideally I'd like to be able to handle everything in the liquid layer by editing the html and css of the store directly. A custom app with API integration is another option but less desirable as it doesn't seem necessary and would appear to be a lot more work.
EDIT: Tried piggybacking the order (thinking orders are unique to users) but it doesn't appear that the order object is created until the checkout is complete so that isn't really useful since I want to be able to attribute the user to a session click that led them to the store.
Thanks,
Alex
You will want to use an App. First, off, that is the only way for you to alter any objects in Shopify. Secondly, you can easily store simple things like counter values on the Customer resource using metafields. Third, anything you do with metafields on the Customer would be easily visible to the customer, since you can expose those metafields using Liquid. Fourth, if you choose to use JS you must use the App Proxy pattern. Shopify will then send your JS XHR payload to your App endpoint in a secure fashion.
So your needs and how to do are not new, they are old skool in Shopify terms and very straightforward to implement.

Adding multiple Cards to a Customer

I am using PHP to add Cards to a Customer
I have related questions so I have posted them together as (1)(2)(3)
I can use the balanced marketplace to verify that the customer has had each of the cards added to their account. I have no problem adding each card.
(1) When I use the following to get the customer object
$customer = \Balanced\Customer::get("/v1/customers/CU34xY6f9bKZzb0kjBxWTUjC");
var_dump($customer);
It only shows the second card added, however balanced marketplace lists both cards associated with the customer. Why is only one showing up in $customer?
(2) The var_dump($customer) gives
"Balanced\Card" ["uri"]=> string(68) "/v1/customers/CU34xY6f9bKZzb0kjBxWTUjC/cards/CCyO8fJPHpaVzypm7L1TFbw"
however the card uri is
/v1/marketplaces/TEST-MP9COksoYlU4rwuakSzwYH6/cards/CCyO8fJPHpaVzypm7L1TFbw
Won't this lead to problems retrieving card info/charging cards?
(3) If I try to add either card again there is no change to $customer or the balanced marketplace. Should I be able to see some sort of error response, if so how?
The documentation "https://docs.balancedpayments.com/1.0/api/customers/#adding-a-card-to-a-customer" gives an Example Response, I am assuming this is changes made to $customer as it does not say how you would view this response.
Both the URIs you posted go to the same Card resource, they just use different API endpoints.
Adding the same card multiple times won't result in an error. When you tokenize (add) a card, a new Card instance is created for the information supplied and you get back a unique URI. Each instance of Card can only be associated with one Customer. Tokenization doesn't check in this manner for "duplicate" Cards because, for example, say a person added their card and then their significant other added it to another service that uses Balanced. You can have multiple tokenized representations of the credit card that can be added to only once Customer each but represent the same credit card.
If you tokenize a card and add it to a Customer, the Customer instance should reflect the new Card URI in its attributes. You might need to reload the Customer instance first. If you're seeing odd behavior, I suggest you swing by #balanced on Freenode IRC where the developers can help you look into what's going on.