CyberSource / cybersource-ios-sdk

The CyberSource InApp SDK enables developers to simply and securely incorporate mobile payments into their iOS applications.
Other
1 stars 1 forks source link

encryptPaymentDataServiceFinished(::) is not called after encrypting card data #14

Open zhmul opened 4 years ago

zhmul commented 4 years ago

iOS SDK Version: 1.0.3 iOS Version: 13.2.2

Expected behavior:

When executing this (given that self conforms to InAppSDKGatewayDelegate):

let merchant = InAppSDKMerchant()

// Fill merchant object with valid data

let card = InAppSDKTransactionObject()

// Fill card object with valid data

let transaction = InAppSDKTransactionObject()

// Fill transaction object with previous valid data

let success = InAppSDKGateway.sharedInstance().performDataEncryption(transaction, with: self)

The expected behavior would be:

Current behavior:

If performDataEncryption is not executed in the main thread, this happens:

MiraEs commented 3 years ago

Hey @zhmul have you been able to figure this out? I'm having a similar issue where this delegate method is also not called for me. Same code implementation.

zhmul commented 3 years ago

Hi @MiraEs! The only way that I found for this to work is call performDataEncryption in the main thread. Only then the delegate method is called back.

crherman7 commented 3 years ago

Hi @zhmul I'm doing something like below but not seeing the delegate function called - any ideas or fixes from what you see below that would help me hit the delegate method?

    @objc(performPaymentDataEncryption:withRejector:)
    func performPaymentDataEncryption(resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) -> Void {
        self.resolve = resolve
        self.reject = reject
        let transactionObject = InAppSDKTransactionObject()

        transactionObject.billTo = self.billingData
        transactionObject.cardData = self.cardData
        transactionObject.merchant = self.merchantData

        InAppSDKSettings.sharedInstance()?.inAppSDKEnvironment = INAPPSDK_ENV_TEST
        InAppSDKSettings.sharedInstance()?.enableLog = true

        DispatchQueue.main.async {
            let result = InAppSDKGateway.sharedInstance()?.performPaymentDataEncryption(transactionObject, with: self) ?? false

            if (result) {
                print("InAppSDK: Request Accepted. Expect the response in the delegate method.")
            } else {
                print("InAppSDK: Request NOT Accepted. Verify the input values if any one is invalid.");
            }
        }
    }

    func encryptPaymentDataServiceFinishedWithGatewayResponse(paramResponseData: InAppSDKGatewayResponse, paramError: InAppSDKError) -> Void {
        if (self.resolve != nil) {
            self.resolve!(paramResponseData)
        }
    }

btw my class signature is:

class AwesomeModule: NSObject, InAppSDKGatewayDelegate {
zhmul commented 3 years ago

Hi @crherman7! I'm doing everything in the main thread, in the same closure: creating the instances of InAppSDKMerchant, InAppSDKCardData, InAppSDKTransactionObject and calling InAppSDKGateway's performPaymentDataEncryption. Only then, I got a delegate call.

Try moving all code lines inside the dispatch queue block.

crherman7 commented 3 years ago

@zhmul thank you so much! In the end encryptPaymentDataServiceFinishedWithGatewayResponse is actually supposed to be encryptPaymentDataServiceFinished but since it's optional xcode never gave me the warning to rename until I put the @objc header on there. In the end you did have the in the original issue description 💯 thanks again!