Payment process in ios v2

payments
swift

#1

Hi there, I’m using your V2 example to structure my inventory/payment flow in an app. I’m looking to access a users’ previously entered and stored card details(Card Number, CVC code, expiry date, etc) - but now that I progress through the flow I see that in the example you’re asked for Shipping/Billing address, and then the order is complete.

Is it by design that there’s no payment process in v2? If so, can anyone specify why?


#2

Hi Eoghan,

In the example app there is no payment information collected, it instead uses a Stripe test token and pays for the order with that as soon as the order is created. There is two API calls made one after the other in that example app -> checkout cart, then pay for order.

In a real life scenario, you’d want to implement a view that maybe sits after collecting user details, which collects the payment information for that user. This means you could checkout the cart, then collect the users card details (or use one of the other payment gateway options), and pay for an order using those details.

Hope this helps!


#3

Hi Craig,

I’ve worked on this and am running into issues using the in built ‘Payment Method/Payment Gateway’ enums. I’ve used the file CollectAddressViewController as a template for this file, but am having issues with assignment the correct variables and such. Is there a template/sample available that Moltin have made?

I’m to demo the system in a couple of weeks so would love to be able to have this functionality, even if it’s with test tokens/purchases. I’d love to demonstrate the flow from start to finish, including getting payment details.

Thanks,
Eoghan


#4

Hi Eoghan,

Our current payment method support for the V2 SDK can be found here. They’re enums, so you fill in the details as you create the enum, e.g:

let paymentInfo = .stripeCard(
    firstName: ...,
    lastName: ...
    cardNumber: ...,
    expMonth: ...,
    expYear: ...,
    cvv: ...
)

You can then use this payment method in when you pay for an order:

Moltin.checkout.pay(forOrderID: orderID, withPaymentMethod: paymentInfo) { result in 
   ...
}

Hope this helps,
Craig


#5

Hi Craig,
So do I make a payment equivelant of say “CollectAddressViewController” in which I take in the values for my card payment, and then in my CheckoutFlowController I navigate to that screen, and that screen will make a ‘paymentInfo’ enum that I’ll then include at the bottom of my CheckoutFlowController?

If that’s too vague a question I’ll try to be more specific, but I’m just trying to wrap my understanding around the way in which I approach this!


#6

That’s exactly right Eoghan!

You’ll want to include text fields that will let you fill in one of those enum cases, such as name, card number, expiry details etc.

Hope that helps


#7

I’ve written out these files now and just have a few errors - in my CollectPaymentViewController, I’m getting an error in my let payment = PaymentType method that says there’s an extra argument ‘lastName’ in call. Is there somewhere I need to declare what’s to be expected in the call?

As well as that I’ve an error in my PaymentGateway file, in my public struct PaymentGateway. Saying the use of JSONAPIDecodable is an undeclared type, do I need to import a specific module/pod for these to work?

Thanks,
E


#8

Have you created your own PublicGateway struct? If so it may be that it’s getting confused between your struct and Moltin’s own, which has JSONAPIDecodable required. This interface should be imported with Gloss I believe, which is installed as part of installing the Moltin V2 pod.

If you take a look at the PaymentMethod enum, this details what properties you’ll need to fulfil. I don’t think we have a PaymentType object.


#9

Ah OK I was confused about that. So the PaymentGateway is already in the project I just need to call the correct objects?

Thank you, that should help me out!


#10

Hi Craig,

Sorry this seems to be tripping me up so I was wondering if I could get more info.

From the PaymentGateway, there are 5 cases, stripeToken/stripeCard etc. How am I to access them from my CollectPaymentViewController?

Also, in my func submitPayment, I have a “let payment = PaymentGateway” method. In the gateway file this struct has a String name/slug. From within this submitPayment method, how am I to correctly call both these cases in my CollectPaymentViewController(.stripeToken, .stripeCard, .braintreeCustomerID, .braintreeToken, .braintreeNonce) as well as the struct PaymentGateway with the correct arguments?

Thanks,
Eoghan


#11

Hi Eoghan,

Once your users have filled in your payment information, you’ll just want to instantiate the relevant enum case, for example, if you wanted to use the Stripe card information, you’d instantiate a variable with that case:

let paymentInfo: PaymentMethod = .stripeCard(
    firstName: firstNameTextField.text,
    lastName: lastNameTextField.text,
    cardNumber: ...,
    expMonth: ...,
    expYear: ...,
    cvv: ...
)

This is what you’ll use when you want to pay for an order.

Hope this helps


#12

Perfect! That’s made it much clearer thank you!

One more question, in the Moltin.checkout.checkout(…) in my CheckoutFlowController - how would I add the paymentInfo argument to that call?


#13

It’s a two step process, you’ll first want to checkout your cart using Moltin.checkout.checkout(…), which will return you an order. Then you can pay for an order using Moltin.checkout.pay(...) - this is where you’d add your payment info in.


#14

Brilliant, that’s up and running. Thank you Craig(again)!


#15

Hi Craig,
Mightn’t be the right place to ask but I thought I’d ask you first as this is where I’ve been introduced to EntryViews. In your CollectAddressViewController you use the setPlaceholder for the title of the EntryView. What I’m doing now is retrieving the users’ address from the database, and I want to set the value of the EntryView to the retrieved value. When I use the setPlaceholder I can see that I’m accessing the correct value, but the setValue isn’t working for me as it’s saying “this class is not key value coding-compliant for the key” - any idea why this is going wrong?


#16

Hi Eoghan,

EntryView is something the previous developer on the SDK wrote. Looks like they’ve created a setPlaceholder method to set the placeholder of the textField, but not created any setText or setValue method to go along with it.

In this case, you should just access the textField directly and set it’s text:

entryView.textField.text = "Your value"

Hope this helps.


#17

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.