Tap-Payments / goSellSDK-iOS

goSell iOS SDK
MIT License
19 stars 20 forks source link

sessionhasfailed to start error showing but no issue with key as I am getting success in response #46

Open HarshitPadalia opened 3 years ago

HarshitPadalia commented 3 years ago
//
//  ViewController.swift
//  TapPaymentSDKDemo
//
//  Created by Harshit Padalia on 15/03/21.
//

import UIKit
import goSellSDK

class ViewController: UIViewController, SessionDelegate, SessionDataSource {

    @IBOutlet weak var button: PayButton!

    var mode: TransactionMode {

           return .purchase
       }
       var customer: Customer? {
           return self.newCustomer
       }

       /// Creating a customer with known identifier received from Tap before.
//       var identifiedCustomer: Customer? {
//
//           return try? Customer(identifier: "cus_to_mer")
//       }

       /// Creating a customer with raw information.
       var newCustomer: Customer? {

           let emailAddress = try! EmailAddress(emailAddressString: "test@gmail.com")
           let phoneNumber = try! PhoneNumber(isdNumber: "91", phoneNumber: "123456789")

           return try? Customer(emailAddress:  emailAddress,
                                phoneNumber:   phoneNumber,
                                firstName:      "test",
                                middleName:    nil,
                                lastName:       "test")
       }
       var currency: Currency? {

           return .with(isoCode: "USD")
       }

       var amount: Decimal {

           return Decimal(120)
       }
       var postURL: URL? {

           return URL(string: "https://tap.company/post")
       }
       var paymentDescription: String? {

           return "jkjk";
       }
       var paymentMetadata: [String : String]? {

           return [:]

       }
       var paymentReference: Reference? {

           return Reference(transactionNumber: "12",
                            orderNumber:       "13")
       }
       var paymentStatementDescriptor: String? {

           return "Payment statement descriptor will be here"
       }
       var require3DSecure: Bool {

           return false
       }

       var receiptSettings: Receipt? {

           return Receipt(email: true, sms: true)
       }
       var allowsToSaveSameCardMoreThanOnce: Bool {

           return false
       }
       var isSaveCardSwitchOnByDefault: Bool {

           return true
       }

    let sesssion : Session? = nil
    override func viewDidLoad() {
        super.viewDidLoad()
        button.isEnabled = true
        button.dataSource = self
        button.delegate = self
        sesssion?.dataSource = self
        updatePayButtonAmount()
        self.button?.updateDisplayedState()
        self.title = "Tap Payment"

    }

    internal func updatePayButtonAmount() {

        self.button?.updateDisplayedState()
    }

        internal func TabPaymentGatewayViewController() {

            self.button?.updateDisplayedState()

        }

    func paymentSucceed(_ charge: Charge, on session: SessionProtocol) {
           print(charge)

//           self.dismiss(animated: true, completion: { self.callback?(charge.identifier,"1")})

       }
       func paymentFailed(with charge: Charge?, error: TapSDKError?, on session: SessionProtocol) {
        if let error = error {
                    let errorMessage:String = "\(error) \n \(error.description)"
                    let alert:UIAlertController  = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
                    let copyAction:UIAlertAction = UIAlertAction(title: "Copy", style: .destructive) { (_) in
                        UIPasteboard.general.string = errorMessage
                    }
                    alert.addAction(copyAction)
                    present(alert, animated: true, completion: nil)
                }
       }

    @IBAction private func addButtonTouchUpInside(_ sender: Any) {

          // self.showPaymentItemViewController()
       }

    func sessionHasStarted(_ session: SessionProtocol) {
          print(session)
      }
      func sessionCancelled(_ session: SessionProtocol) {
          print(session)
          DispatchQueue.main.async{
              self.dismiss(animated: true, completion: {
                 // self.callback?("0","0")
              })
          }

      }
      func sessionHasFailedToStart(_ session: SessionProtocol) {
        print(session)
      }
}

My code as above and I am getting this response when I tap on pay button. Request:

GET https://api.tap.company/v2/init Headers: Authorization: Bearer XXXX application: requirer_sim_network_name=|app_locale=en|requirer_device_model=iPhone|requirer=SDK|requirer_sim_country_iso=|requirer_device_type=iPhone|requirer_os_version=14.2|requirer_version=2.2.45|requirer_os=iOS|requirer_device_name=iPodtouch7thgeneration|app_id=harshit.TapPaymentSDKDemo

2021-03-15 15:04:19.072250+0530 TapPaymentSDKDemo[20361:382342] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed Response:

URL: https://api.tap.company/v2/init HTTP status code: 200 Headers: referrer-policy: no-referrer Strict-Transport-Security: max-age=15552000; includeSubDomains Content-Length: 1557 feature-policy: camera 'none';autoplay 'none' Date: Mon, 15 Mar 2021 09:34:20 GMT Etag: W/"615-PefWMrBXbcpuLOAcVfUCOBGZbCk" x-dns-prefetch-control: off content-security-policy: img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self' x-content-security-policy: img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self' x-download-options: noopen x-content-type-options: nosniff x-webkit-csp: img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self' x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block Content-Type: application/json; charset=utf-8 Body: { "data" : { "encryption_key" : "-----BEGIN PUBLIC KEY——XXXXXX——END PUBLIC KEY-----\n", "key_type" : "secret_key", "live_mode" : false, "livemode" : false, "merchant" : { "background" : { "url" : "https:\/\/goselljslib.b-cdn.net\/photo-1497366754035-f200968a6e72.jpeg" }, "logo" : "https:\/\/www.gotapnow.com\/web\/tapimg.aspx?cst=7538289", "name" : "" }, "merchant_id" : “XXXXXX”, "merchant_name" : "", "permission" : { "card_wallet" : true, "pci_dss" : false, "threeDSecure" : true }, "permissions" : [ "card_wallet_enabled" ], "private_key" : “*****” //sandbox publishable key used here, "sdk_settings" : { "otp_resend_attempts" : 3, "otp_resend_interval" : 60, "status_display_duration" : 5 }, "session_token" : “*”*** }, "status" : "success" }

TAP SDK KNOWN ERROR : Serialization Error description : The data couldn’t be read because it is missing. keyNotFound(CodingKeys(stringValue: "verified_application", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "data", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: \"verified_application\", intValue: nil) (\"verified_application\").", underlyingError: nil)) URL : https://api.tap.company/v2/init Error Response Body : ["data": { "encryption_key" = "-----BEGIN PUBLIC KEY——XXXXX——END PUBLIC KEY-----\n"; "key_type" = "secret_key"; "live_mode" = 0; livemode = 0; merchant = { background = { url = "https://goselljslib.b-cdn.net/photo-1497366754035-f200968a6e72.jpeg"; }; logo = "https://www.gotapnow.com/web/tapimg.aspx?cst=7538289"; name = ""; }; "merchant_id" = XXXXX; "merchant_name" = ""; permission = { "card_wallet" = 1; "pci_dss" = 0; threeDSecure = 1; }; permissions = ( "card_wallet_enabled" ); "private_key" = “****” ; //sandbox publishable key used here "sdk_settings" = { "otp_resend_attempts" = 3; "otp_resend_interval" = 60; "status_display_duration" = 5; }; "session_token" = “****”; }, "status": success] Error URL Body : <NSHTTPURLResponse: 0x6000033b8f00> { URL: https://api.tap.company/v2/init } { Status Code: 200, Headers { "Content-Length" = ( 1557 ); "Content-Type" = ( "application/json; charset=utf-8" ); Date = ( "Mon, 15 Mar 2021 09:34:20 GMT" ); Etag = ( "W/\"615-PefWMrBXbcpuLOAcVfUCOBGZbCk\"" ); "Strict-Transport-Security" = ( "max-age=15552000; includeSubDomains" ); "content-security-policy" = ( "img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self'" ); "feature-policy" = ( "camera 'none';autoplay 'none'" ); "referrer-policy" = ( "no-referrer" ); "x-content-security-policy" = ( "img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self'" ); "x-content-type-options" = ( nosniff ); "x-dns-prefetch-control" = ( off ); "x-download-options" = ( noopen ); "x-frame-options" = ( SAMEORIGIN ); "x-webkit-csp" = ( "img-src imgur.com; script-src 'self'; object-src 'none'; frame-ancestors 'none'; default-src 'none'; base-uri 'self'; form-action 'self'" ); "x-xss-protection" = ( "1; mode=block" ); } }

After this logs sessionHasFailedToStart method called and then payment failed method call

varunDM commented 3 years ago

Same issue. Found any solutions?

AAlboghdady commented 3 years ago

I had this issue and it was about the secret key and the bundle id. The tap team gave me another key and it worked.