veritrans / Veritrans-ios-sdk

The new iOS SDK
MIT License
14 stars 33 forks source link

Crash when using credit card payment #387

Closed verreliocr closed 3 months ago

verreliocr commented 5 years ago

I try to specify my payment to credit card, i've tried one-click and 2-click and it still crash... The error says :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

jukiginanjar commented 5 years ago

what version you using @verreliocr ?

verreliocr commented 5 years ago

@jukiginanjar using version 1.13.1 on midtrans sdk, and swift 4

jukiginanjar commented 5 years ago

can you paste your code here?

jukiginanjar commented 5 years ago

you SDK implementation code @verreliocr

verreliocr commented 5 years ago
MidtransCreditCardConfig.shared().paymentType = .oneclick
MidtransCreditCardConfig.shared().saveCardEnabled = true
//1-click need 3D secure enabled
MidtransCreditCardConfig.shared().tokenStorageEnabled = true
//1-click need 3ds enabled
MidtransCreditCardConfig.shared().secure3DEnabled = true

for 1-click setup

let transactionDetails = MidtransTransactionDetails(orderID: topupId,
                                                    andGrossAmount: NSNumber(integerLiteral: grossAmount))
let itemDetails: [MidtransItemDetail] = [MidtransItemDetail(itemID: "topup",
                                                            name: "topup",
                                                            price: NSNumber(integerLiteral: grossAmount),
                                                            quantity: NSNumber(integerLiteral: 1))]
let tokenResponse = MidtransTransactionTokenResponse(dictionary: tokenDict)
tokenResponse!.transactionDetails = transactionDetails
tokenResponse!.itemDetails = itemDetails

var vc = MidtransUIPaymentViewController()
vc = MidtransUIPaymentViewController.init(token: tokenResponse!, andPaymentFeature: `.MidtransPaymentFeatureCreditCard)`

and thats for payment view controller @jukiginanjar

jukiginanjar commented 5 years ago

@verreliocr MidtransTransactionTokenResponse is retrieved with this function MidtransMerchantClient.shared().requestTransactionToken..., you cannot create that method manually.

verreliocr commented 5 years ago

I used that implementation on other payment channel, and it seems work well are MidtransTransactionTokenResponse(dictionary: [AnyHashable : Any]) can do it?? ok I'll try to change it @jukiginanjar

jukiginanjar commented 5 years ago

you cannot, MidtransTransactionTokenResponse is response from token request

verreliocr commented 5 years ago
let transactionDetails = MidtransTransactionDetails(orderID: topupId,
                                                        andGrossAmount: NSNumber(integerLiteral: grossAmount))
    let itemDetails: [MidtransItemDetail] = [MidtransItemDetail(itemID: "topup",
                                                                name: "topup",
                                                                price: NSNumber(integerLiteral: grossAmount),
                                                                quantity: NSNumber(integerLiteral: 1))]

    let customerDetails = MidtransCustomerDetails()
    let getUser = try! Realm().objects(userData.self).last!
    customerDetails.firstName = getUser.name
    customerDetails.email = getUser.email
    customerDetails.phone = getUser.phone

    MidtransMerchantClient.shared().requestTransactionToken(with: transactionDetails!, itemDetails: itemDetails, customerDetails: customerDetails) { (response, error) in
      if (response != nil) {

        var vc = MidtransUIPaymentViewController()
        vc = MidtransUIPaymentViewController.init(token: response!, andPaymentFeature: .MidtransPaymentFeatureCreditCard)
        let midTransFont: MidtransUIFontSource = MidtransUIFontSource.init(fontNameBold: AppFont.Style.bold.rawValue, fontNameRegular: AppFont.Style.regular.rawValue, fontNameLight: AppFont.Style.light.rawValue)
        MidtransUIThemeManager.applyCustomThemeColor(AppColor.atlantis, themeFont: midTransFont)
        vc.paymentDelegate = self
        self.present(vc, animated: true)
      } else {
        //handle error
      }

I try to use it like that, and it still crash, it says : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[4]' @jukiginanjar

jukiginanjar commented 5 years ago

@verreliocr can you make sure if you've got the token from response?

verreliocr commented 5 years ago

oh sorry i didn't mention it, but now it crash when function MidtransMerchantClient.shared().requestTransactionToken is called

verreliocr commented 5 years ago

I tried use this way let tokenResponse = MidtransTransactionTokenResponse.modelObject(with: tokenDict, transactionDetails: transactionDetails, customerDetails: customerDetails, itemDetails: itemDetails) and it didn't crash!

But, it return an alert, the alert says

Transaction unsuccessful. Please try again with another card or with a different payment method

@jukiginanjar

jukiginanjar commented 5 years ago

hi @verreliocr I think it's because you create MidtransCustomerDetails without set all of its properties, I saw you only set firstName, email & phoneNumber there.