#Svenson

1 messages ยท Page 1 of 1 (latest)

abstract pastureBOT
left cloak
#

What specific issue are you encountering? Are there errors? Are you following a guide/doc?

tender hawk
#

hey man

#
 func beginPushProvisioning() {
    let config = STPPushProvisioningContext.requestConfiguration(
      withName: "Jenny Rosen", // the cardholder's name
      description: "RocketRides Card", // optional; a description of your card
      last4: "4242", // optional; the last 4 digits of the card
      brand: .visa // optional; the brand of the card
    )
    let controller = STPFakeAddPaymentPassViewController(requestConfiguration: config, delegate: self)
    self.present(controller!, animated: true, completion: nil)
  }

#

this is the code I am using

#

and this is the error I get

#

and swift is not my expertise, so I do not know if I am missing something

#

from what I see, I am putting invalid delegate type

left cloak
#

Are you following a specific guide? Its not clear to me what you're actually trying to do

tender hawk
#

I am following this guie

#

this is my first interaction with swift, and i have no idea how to continue

#

but other steps are bugging me

valid quail
#

hmm, using our Issuing SDKs and the native Apple provisioning SDKs to add cards to Apple Pay is one of the most complicated things you could do really and not something for a junior mobile developer

valid quail
# tender hawk

what's the error there exactly when you click on the red section to the right of the line?

#

to take a step back too, are you sure you need to use Issuing and this integration at all? What are you actually trying to do at a higher level/what's your task?

tender hawk
#

"Thread 11: Assertion failed: Invalid parameter not satisfying: delegate != nil"

#

this is the error I get

#

yeah, I am 100% sure I need this

valid quail
#

can you share the complete code of the entire ViewController in text form?

tender hawk
#

can I dm you with that?

valid quail
# tender hawk yeah, I am 100% sure I need this

just want to be sure. You definitely need to issue credit cards to users of your marketplace and let them add those cards to their Apple Pay wallets through a flow in your company's iOS app? You are not just trying to accept payments using Apple Pay from end-customers?

valid quail
tender hawk
#

yup, user will need to add this card to their wallet

#

just a min, will share you files now

#
import Foundation
import PassKit
import Capacitor
import Stripe
import StripeApplePay
import Alamofire


@available(iOS 13.4, *)
@objc(WalletPlugin)
public class WalletPlugin: CAPPlugin {
  @objc public func checkEligible(_ call: CAPPluginCall) {
      var showButton = false
      let value = call.getObject("value", JSObject())
      let accountIdentifier = value["primaryAccountIdentifier"] ?? ""
      if (value["eligible"] != nil) &&
            PKPassLibrary().canAddSecureElementPass(primaryAccountIdentifier: accountIdentifier as! String) {
        showButton = true
      } else {
        showButton = false
      }
      var hideButton: [String: Bool] = ["showButton": showButton]
      call.resolve(hideButton);
  }
    
    @objc public func testingCard(_ call: CAPPluginCall) {
        let implementation = Wallet()
        implementation.beginPushProvisioning()
        var hideButton: [String: Bool] = ["showButton": true]
        call.resolve(hideButton);
    }
}
#

this is one part of it

#

and this is different file in which I have uicontroller

#
import Stripe
import PassKit
import Alamofire

public class Wallet: UIViewController {
var pushProvisioningContext: STPPushProvisioningContext? = nil
  @IBOutlet weak var addPassButton: PKAddPassButton!
    public weak var delegate: PKAddPaymentPassViewControllerDelegate? = nil

    func beginPushProvisioning() {
        let config = STPPushProvisioningContext.requestConfiguration(
        withName: "Jenny Rosen", // the cardholder's name
        description: "RocketRides Card", // optional; a description of your card
        last4: "4242", // optional; the last 4 digits of the card
        brand: .visa // optional; the brand of the card
      )
        print(config)
        let controller = STPFakeAddPaymentPassViewController(requestConfiguration: config, delegate: delegate)
        self.present(controller!, animated: true, completion: nil)
    }
}

#

plus extensions

extension Wallet {
    public func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, generateRequestWithCertificateChain certificates: [Data], nonce: Data, nonceSignature: Data, completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void) {
    self.pushProvisioningContext = STPPushProvisioningContext(keyProvider: self)
    // STPPushProvisioningContext implements this delegate method for you, by retrieving encrypted card details from the Stripe API.
    self.pushProvisioningContext?.addPaymentPassViewController(controller, generateRequestWithCertificateChain: certificates, nonce: nonce, nonceSignature: nonceSignature, completionHandler: handler);
  }
}

extension Wallet: STPIssuingCardEphemeralKeyProvider {
    public func createIssuingCardKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
        // This example uses Alamofire for brevity, but you can make the request however you want
        AF.request("",
                   method: .post,
                   parameters: ["api_version": apiVersion])
        .responseJSON { response in
            switch response.result {
            case .failure(let error):
                completion(nil, error)
            case .success:
                if let data = response.data {
                    do {
                        let obj = try JSONSerialization.jsonObject(with: data, options: []) as! [AnyHashable: Any]
                        completion(obj, nil)
                    } catch {
                        completion(nil, error)
                    }
            }
            }

        }
    }
}

valid quail
#

i..e you need your VC to implement that interface so that when you pass the instance of your VC as self to STPFakeAddPaymentPassViewController it is a valid delegate

tender hawk
#

so vc is delegate?

#

do you have an example of that

valid quail
#

of what exactly? The docs have an example of the extension

tender hawk
#

"delegate"

#

what should I put as argument fro delegate

valid quail
#

self

tender hawk
#

that fails for me

valid quail
#

I know yes. For that to work though, self needs to implement the extension

#

extensions are like abstract interface in Java if you know that. You have a like a Class Wallet (in your case) and then you can do extension Wallet:SomeInterface {...} to provide the implementation

tender hawk
valid quail
#

press the Fix button.

tender hawk
#

then it creates 4 or 5 functions

valid quail
#

it does yes

tender hawk
#

now it runs without any errors

#

that's nice

#

that's not possible to test on actual device in EU right?

valid quail
#

I don't know I'm afraid, I'm not familiar with this feature

tender hawk
#

okay

#

thank you for your time

#

I appreciate it

tender hawk
#

could this error be becasue of simulator?

#

Attempt to present <Stripe.STPFakeAddPaymentPassViewController: 0x7ff1ade33f10> on <App.Wallet: 0x7ff1ade33b70> (from <App.Wallet: 0x7ff1ade33b70>) whose view is not in the window hierarchy.
โšก๏ธ TO JS {"showButton":true}

valid quail
#

I don't think so, it's more a general iOS thing

#

where is testingCard called from in your code?

tender hawk
#

I am calling it from javascript file, this is just a plugin I made with swift

valid quail
valid quail
tender hawk
#

angular

valid quail
#

I didn't even know you can call iOS code from Angular

tender hawk
#

I can not go into too much details unfortunately

#

it's actually ionic with angular

#

and capacitor

valid quail
#

yeah unfortunately all of those technologies are unsupported by Stripe and nobody internally uses them(we only really have internal knowledge of React, React Native, and native iOS/Android) so I'm extremely limited in what I can help you with there

tender hawk
#

all good, I appreciate the time and will to help

valid quail
#

in any case that type of error is usually caused by calling a function that tries to present a view(in this case self.present(controller!, animated: true, completion: nil)) from the wrong context, like before the enclosing View(Wallet in your case) has fully appeared

tender hawk
#

okay

#

that make sense

#

so i got to figure out how should wallet view appear firstly

valid quail
#

I would say so yes, the idea is your Wallet should already exist and then you have a button in that view that when pressed, triggers the provisioning stuff

tender hawk
#

okay, I think I got it

#

I am only doing the triggering provisionoing stuff now

#

thought that's gonna trigger the wallet to open also

valid quail
tender hawk
#

thank you

#
        let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
        vc.present(controller!, animated: true, completion: nil)

#

this looks helpful

valid quail
#

yeah, getting the root view controller and presenting on to that might make sense.

tender hawk
#

findViewControllerPresenter this would be the root controller?

#

sorry for stupid questions

#

first time doing Swift

#

and I am aware that it's not the best place to start

#

but need that for the app so

past cave
#

Hello ๐Ÿ‘‹
Taking over as karllekko needs to step away

tender hawk
#

hey

#

thank you

#

I can not figure out how to use this

#

let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
vc.present(controller!, animated: true, completion: nil)

past cave
#

Are you seeing any specific errors?

tender hawk
#

"Cannot find 'findViewControllerPresenter' in scope"

#

"'nil' requires a contextual type"

past cave
#

Umm can you try defining that function in scope of the class?

    // Note: creating a UIViewController inside here results in a nil window
    // This is a bit of a hack: We traverse the view hierarchy looking for the most reasonable VC to present from.
    // A VC hosted within a SwiftUI cell, for example, doesn't have a parent, so we need to find the UIWindow.
    var presentingViewController: UIViewController =
        uiViewController.view.window?.rootViewController ?? uiViewController

    // Find the most-presented UIViewController
    while let presented = presentingViewController.presentedViewController {
        presentingViewController = presented
    }

    return presentingViewController
}```
tender hawk
#

okay, thanks

#

now I am getting a different error

#
  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Call must be made on main thread'
past cave
#

Hmm that's quite generic ๐Ÿ˜…
Does it occur when you call .present or before that?

tender hawk
#

when I call .present

past cave
#

I think in order to call the function from main thread, you'd want to put the code in-between

  // your code here
}```
tender hawk
#

okay

#

i am not getting 33333

#

will try with dispatch

past cave
#

๐Ÿ‘

tender hawk
#

okay, now I am getting somewhere

#

getting real close

past cave
#

that's great

#

๐Ÿคž

tender hawk
#

I am missing something here right?

past cave
#

Not sure, what's going on?
Any errors or anything?

#

can you try logging error before calling dismiss?

tender hawk
#

if you look my last image

#

that's the error

#

something with exceding the limit and make sure to call completionHandler

#

that's probably this

#

the first part in extension

past cave
#

I don't see an error in the last image? ๐Ÿ˜…

#

I just see some code

tender hawk
past cave
#

OH ok ok

#

yeah looks like the completion handler isn't getting called

#

I need to step away soon so checking if there were any updates @tender hawk

tender hawk
#

I am good

#

thank you

#

very much

#

if I can provide a beer

#

i will be happy do it

#

you helped a lot

past cave
#

Ah awesome ๐Ÿ™‚ Glad we were able to help