BrainTree UIDropIn VC not display amount in iOS integration - ios

I create a demo for payment using Braintree iOS v4 SDK. All thinks going great but I have a query regarding the amount. I used DropIN VC for UI.
//MARK: Show Dropin VC
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
request.amount = "1.0"
request.currencyCode = "USD"
request.threeDSecureVerification = true;
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
if (result.paymentOptionType == BTUIKPaymentOptionType.applePay){
controller.dismiss(animated: true, completion: nil)
self.paymentApplePay()
}else{
print(result.paymentMethod?.nonce as Any)
print(result.description)
}
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}
when I select Paypal option I redirect to the checkout screen. check images
here is the problem that I can't see the amount I entered at the time of the request. How can I see that? Thanks in advance.

Related

rootViewController not loading after calling it, using -> present(viewControllerToPresent: UIViewController, animated: true, completion: nil)

My rootViewController works and loads fine. However, when I call it using the present(viewControllerToPresent: UIViewController, animated: true, completion: nil) from another viewController I get nothing but a black screen.
I looked all over the stackOverflow but only found solutions for storyboard users. I am doing this programmatically
#objc func handleLogin() {
print("LOGIN BUTTON TOUCHED")
guard let email = emailTextField.text, let password = passwordTextField.text else {
print("Form is not valid.")
return
}
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if error != nil {
print(error!)
return
}
let viewController = RootViewController()
*** self.present(viewController, animated: true, completion: nil)
print("Logged in")
}
}
There is nothing wrong with self.present(viewController, animated: true, completion: nil)
I think your RootViewController() is already presented. The black screen you see is might be the one without any data? I am not sure, will need your code for that class.
Another approach you can consider is to replace the real rootViewController from current uiWindow like this
#objc func handleLogin() {
print("LOGIN BUTTON TOUCHED")
guard let email = emailTextField.text, let password = passwordTextField.text else {
print("Form is not valid.")
return
}
Auth.auth().signIn(withEmail: email, password: password) { [weak self] (user, error) in
guard let strongSelf = self else { return }
guard error == nil else { return }
guard let user = user else { return }
UIApplication.shared.keyWindow?.rootViewController = RootViewController()
print("Logged in")
}
}
you've created a new instance(RootViewController) and it must be black .. your not referring to your RootViewController

Cannot get Plaid sandbox to work on iOS with Swift 3

When I use the un:user_good and pw:pass_good I get the attached screen
And it does not return a accessToken
I have already added my public key in my AppDelegate
[![#IBAction fu][1]][1]nc plaidConnectButton(_ sender: Any) {
let plaidLink = PLDLinkNavigationViewController(environment: .tartan, product: .connect)!
plaidLink.linkDelegate = self
plaidLink.providesPresentationContextTransitionStyle = true
plaidLink.definesPresentationContext = true
plaidLink.modalPresentationStyle = .custom
self.present(plaidLink, animated: true, completion: nil)
}
func linkNavigationContoller(_ navigationController: PLDLinkNavigationViewController!, didFinishWithAccessToken accessToken: String!) {
print("success \(accessToken)")
myAPIClient.connectAddBank(bankToken: accessToken, completion:{
(error) in
if(error != nil) {
print(error.debugDescription)
} else {
print("successfully added bank")
self.dismiss(animated: true, completion: nil)
}
})
}
func linkNavigationControllerDidFinish(withBankNotListed navigationController: PLDLinkNavigationViewController!) {
print("Manually enter bank info?")
self.performSegue(withIdentifier: "unlistedBankSegue", sender: self)
}
func linkNavigationControllerDidCancel(_ navigationController: PLDLinkNavigationViewController!) {
self.dismiss(animated: true, completion: nil)
}
Please help
Set your environment to .sandbox during the init process.
Plaid support link for this: https://github.com/plaid/link/issues/140

Apple Pay and Stripe: Token not being sent to Stripe

Set up Apple Pay in my app and it seems to work fine when running on device. Using Stripe as the payment processor but it is not sending the token to Stripe, but seems to be charging the credit card listed in my iPhone's digital wallet.
The problem I am having is that once I press the "Pay with Touch ID", I get a check mark in my Apple Pay sheet but the following page appears in Xcode:
Code for Apple Pay & Stripe
var paymentSucceeded: Bool = false
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
didAuthorizePayment payment: PKPayment, completion: #escaping (PKPaymentAuthorizationStatus) -> Void) {
STPAPIClient.shared().createToken(with: payment) { (token, error) in
print("I am here")
if error != nil {
completion(.failure)
print("failed")
} else {
self.paymentSucceeded = true
completion(.success)
print("woohoo")
}
self.createBackendCharge(with: token!, completion: completion)
print("created Backend Charge")
self.postStripeToken(token: token!)
print("posted stripe token")
}
} // paymentAuthorizationViewController( didAuthorizePayment )
func createBackendCharge(with token: STPToken, completion: #escaping (_: PKPaymentAuthorizationStatus) -> Void) {
//We are printing Stripe token here, you can charge the Credit Card using this token from your backend.
print("Stripe Token is \(token)")
completion(.success)
} // createBackendCharge func
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: {
if (self.paymentSucceeded) {
// show a receipt page
}
})
} // paymentAuthorizationViewControllerDidFinish()
#IBAction func applePayPressed(_ sender: UIButton) {
// we have already accepted the request from viewDriverBids
// all that remains is to complete payment
print("enable apple pay")
// send user to Apple Pay to make payment
let paymentNetworks = [PKPaymentNetwork.visa, .masterCard, .interac, .discover, .amex]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
paymentRequest = PKPaymentRequest()
paymentRequest.currencyCode = "CAD"
paymentRequest.countryCode = "CA"
paymentRequest.merchantIdentifier = "merchant.com.xxx"
paymentRequest.supportedNetworks = paymentNetworks
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.requiredShippingAddressFields = [.all]
paymentRequest.paymentSummaryItems = self.rydes()
let applePayVC = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
applePayVC.delegate = self
self.present(applePayVC, animated: true, completion: {
rRydeHandler.Instance.completeApplePay()
self.paymentComplete = true
self.updateDriverInfoView()
})
} else {
print("Tell the user they need to set up Apple Pay!")
}
} // applePayPressed func ACTION
backend server func
func postStripeToken(token: STPToken) {
let URL = "http://localhost/donate/payment.php"
let params = ["stripeToken": token.tokenId,
"amount": Int(self.driverInfoView.rydeFare.text!)!,
"currency": "cad",
"description": self.riderName] as [String : Any]
let manager = AFHTTPSessionManager()
manager.post(URL, parameters: params, success: { (operation, responseObject) -> Void in
if let response = responseObject as? [String: String] {
let alertController = UIAlertController(title: response["status"], message: response["message"], preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}) { (operation, error) -> Void in
self.handleError(error as NSError)
print(error)
}
}
How can I resolve this issue?
Enable exception breakpoints then Xcode should crash on the line that is causing the issue.
It is almost certainly caused by one of the ! in your code.
Force unwrapping values is very dangerous. It's always better and safer to unwrap it in a guard let or if let.

Why a view (Activity indicator) not getting disappeared?

I've written almost identical code for another function and it works - but for some reason isn't working here. I just want to add this gray view with the activity indicator while the API is retrieving data from the server, and then hide it when the servers returns the data... the error label is updated appropriately, but the view never disappears... (grayLoadingView - this view contains the activity indicator)
#objc private func signUpButtonPressed() {
print("sign up pressed")
if validateTextFields() {
**//start activity indicator
grayLoadingView.isHidden = false**
createNewUser(username: usernameTextField.text!, email: emailTextField.text!, password: passwordTextField.text!, completionHandler: { (message) in
print("message-> \(message)")
**//hide activity indicator
self.grayLoadingView.isHidden = true**
if message == "Account created successfully" {
OperationQueue.main.addOperation {
self.dismiss(animated: false, completion: nil)
let nextScreen = HomeScreenViewController()
nextScreen.username = self.usernameTextField.text!
let newNavController = UINavigationController(rootViewController: nextScreen)
self.present(newNavController, animated: true, completion: nil)
}
} else {
DispatchQueue.main.async {
//display error message
self.errorLabel.isHidden = false
self.errorLabel.text = message
}
}
})
} else {
print("empty")
}
}

Swift GameCenter not behaving properly

I have 2 problems I am experiencing with GameCenter.
If a player is not signed into GameCenter, after if gives you the alert saying you are not signed in, I am no longer able to click any buttons I have on my view.
If a player is signed into GameCenter, after accessing the Leaderboards, pressing “done” will not dismiss the leaderboard view.
Here is my code that relates to GameCenter:
GameViewController:
func authPlayer() { // Gets called in ViewDidLoad
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {
(view, error) in
if view != nil {
self.presentViewController(view!, animated: true, completion: nil)
}
else {
print(GKLocalPlayer.localPlayer().authenticated)
}
}
}
GameScene:
if gameCenterBtn.containsPoint(location) { // In touches began for touch in touches
saveHighScore(highLevel)
let viewController = self.view!.window?.rootViewController
let gcvc = GKGameCenterViewController()
viewController?.presentViewController(gcvc, animated: true, completion: nil)
}
func saveHighScore(number : Int) {
if GKLocalPlayer.localPlayer().authenticated {
let scoreReporter = GKScore(leaderboardIdentifier: "myLeaderBoardID")
scoreReporter.value = Int64(number)
let scoreArray : [GKScore] = [scoreReporter]
GKScore.reportScores(scoreArray, withCompletionHandler: nil)
}
}
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) {
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
Any and all help would be appreciated
1) Not sure this will help, but your login code is not quite correct. If there is no login view controller doesnt necessarily mean the player is signed in. You are also not handling the optional error. Try this instead.
localPlayer.authenticateHandler = { [unowned self] (viewController, error) in // will handle login changes also
if let error = error {
print(error.localizedDescription)
return
}
if let viewController = viewController {
self.presentViewController(viewController, animated: true, completion: nil)
}
else if self.localPlayer.authenticated {
print("Player authenticated")
}
else {
print("Player not authenticated")
}
}
I am not sure why your gameViewCntroller will not respond. Are you not just loading the first SKScene in your gameViewController.
Could you describe further, maybe with some code, of what does not work afterwards.
2) Its not dismissing the screen because you did not set the delegate.
You code where you are creating the Game Center viewController should look like this
let viewController = self.view?.window?.rootViewController
let gcvc = GKGameCenterViewController()
gcvc.gameCenterDelegate = self // YOU FORGOT THIS LINE
viewController?.presentViewController(gcvc, animated: true, completion: nil)

Resources