Code Monkey home page Code Monkey logo

Comments (4)

ahoshaiyan avatar ahoshaiyan commented on June 22, 2024

Could you please share your code (only the portion where you use the SDK) and steps to reproduce the problem

from moyasar-ios-pod.

 avatar commented on June 22, 2024

@ahoshaiyan,

Please find the below code snippet of integration of Moyassar SDK.

Step - 1: AppDelegate.Swift

func initMyasarPayment() {
     do {
          try Moyasar.setApiKey(MOYASAR_TEST_PUBLISH_KEY)
          print("Moyasar Payment initialization successfully")
     } catch (let e) {
          print("Moyasar Payment initialization error \(e)")
     }
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {  
     //Here we have some another code for navigation and initialization

     initMyasarPayment()

     return true
}

Here, I'm getting a success message "Moyasar Payment initialization successfully" when the application is launched.

Step - 2: SwiftUI PaymentView

import SwiftUI
import MoyasarSdk

struct MoyasarView: View {
    @SwiftUI.State var amount: Int = 0
    @SwiftUI.State var currency: String = "SAR"
    @SwiftUI.State var description: String = ""
    @SwiftUI.State var metadata: [String: String] = [:]
    
    func handlePaymentResult(result: PaymentResult) {
        switch result {
        case .completed(let payment):
            print("Payment Completed \(payment)")
            self.handlePaymentResultSuccess(payment)
        case .failed(let error):
            print("Payment Failed \(error)")
            self.handlePaymentError(error)
        case .canceled:
            print("Payment Canceled")
        }
    }
    
    func handlePaymentResultSuccess(_ payment: ApiPayment) {
        switch payment.status {
        case "paid":
            // Handle Paid!
            print("handlePaymentResult Paid \(payment.status)")
            break
        default:
            // Handle other status like failed
            print("handlePaymentResult Default \(payment.status)")
            break
        }
    }
    
    func handlePaymentError(_ error: Error) {
        guard let err = error as? MoyasarError else { return }
        
        switch err {
        case .apiKeyNotSet:
            print("handlePaymentError apiKeyNotSet \(err.localizedDescription)")
        case .invalidApiKey(let e):
            print("handlePaymentError invalidApiKey \(e)")
        case .networkError(let e):
            print("handlePaymentError networkError \(e)")
        case .authorizationError(let e):
            print("handlePaymentError authorizationError \(e)")
        case .apiError(let e):
            print("handlePaymentError apiError \(e)")
        case .unexpectedError(let e):
            print("handlePaymentError unexpectedError \(e)")
        }
    }
    
    var body: some View {
        let paymentRequest = PaymentRequest(
            amount: amount,
            currency: currency,
            description: description,
            metadata: metadata
        )
        CreditCardView(request: paymentRequest, callback: handlePaymentResult)
    }
}

struct MoyasarView_Previews: PreviewProvider {
    static var previews: some View {
        MoyasarView()
    }
}

Here, I created Paymentview in SwiftUI that can initialize the PaymentRequest and display the payment view from Moyasar SDK.

Step - 3: Open the PaymentView from another screen.

let moyasarView = UIHostingController(rootView: MoyasarView(amount: _finalAmount, currency: _currency, description: "Payment from iOS", metadata: ["numberInvoice" : invoice.numberInvoice]))
self.navigationController?.pushViewController(moyasarView, animated: true)

Here, I'm opening the Moyasar Payment screen view

Following the above steps, I got the below output.
Screenshot-1: https://drive.google.com/file/d/1-iGoDWPfdomO045kYTALJStn7tGjCrkP/view?usp=sharing
The above screenshot describes that I can able to get the Moyasar Payment screen view after adding the above code.

Screenshot-2: https://drive.google.com/file/d/1liDh9OVd4-LP1P9UDLWAV1ohpobbic7V/view?usp=sharing
Screenshot 2 described that I can even get the receipt after entering the payment details and clicking on the "Pay" button on the Moyasar Payment view screen.

Issue


Now, The issue is that by following the above steps, I never get the callbacks in any handler handlePaymentResult during and after the transaction of payment and even I never get to know whether the payment gets successes or failed until getting any callback from the Moyasar SDK. I need the details of the transaction that needs to send to our server after completing the payment.

Please help me with that part. Thanks in advance.

from moyasar-ios-pod.

 avatar commented on June 22, 2024

@ahoshaiyan ,

I investigated the issue in depth and found that the problem is appeared due to some UI issue in small resolution device. I tried to run the same code in "iPhone 14 Pro Max" device and can able to see the full page. Previously, I tried to run the same application on iPhone SE that is having a small resolution and due to that bottom part is not accessible and scrollable.

In iPhone 14, I can able to get the call back of transaction data. It's working fine now.

Screenshots

iPhone SE screenshot: https://drive.google.com/file/d/1NGfFfwSt3W1SAezZjRRIkE0a3mVfnrhe/view?usp=sharing
iPhone 14 Max Pro screenshot: https://drive.google.com/file/d/1S7uySFvaiqm5LUo8KYipXygFrePLGvM2/view?usp=sharing

Issue


Now the issue is, I can't able to scroll and see the full UI of the transaction page on a small resolution device [iPhone SE]. Please help me with that.

Thanks in advance.

from moyasar-ios-pod.

mohmedahmed11 avatar mohmedahmed11 commented on June 22, 2024

how I can used in UIkit

from moyasar-ios-pod.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.