Skip to content

Commit

Permalink
feat(ios): hide drawer on didSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
mortend committed Nov 24, 2021
1 parent 7f334b9 commit b17e58b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ios/AdyenDropInModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AdyenDropInModule: NSObject {

private var apiClient: DefaultAPIClient?

private var actionComponent: AdyenActionComponent?

private var dropInConfiguration: DropInComponent.Configuration? = nil

private var resolveCallback: RCTResponseSenderBlock? = nil
Expand Down Expand Up @@ -217,6 +219,7 @@ class AdyenDropInModule: NSObject {
let environment = Environment(baseURL: baseUrl)
let apiContext = APIContext(environment: environment, clientKey: clientKey)
self.apiClient = DefaultAPIClient(apiContext: apiContext)
self.actionComponent = AdyenActionComponent(apiContext: apiContext)

do {
self.resolveCallback = resolveCallback
Expand Down Expand Up @@ -251,7 +254,7 @@ class AdyenDropInModule: NSObject {

internal func finish(with response: PaymentsResponse) {
let success = response.resultCode == .authorised || response.resultCode == .received || response.resultCode == .pending
currentComponent?.finalizeIfNeeded(with: success)
actionComponent?.finalizeIfNeeded(with: success)

presenter?.dismiss(animated: true) { [weak self] in
print("Dismiss successfully")
Expand All @@ -268,7 +271,7 @@ class AdyenDropInModule: NSObject {

internal func finish(with resultCode: ResultCode) {
let success = resultCode == .authorised || resultCode == .received || resultCode == .pending
currentComponent?.finalizeIfNeeded(with: success)
actionComponent?.finalizeIfNeeded(with: success)

presenter?.dismiss(animated: true) { [weak self] in
print("Dismiss successfully")
Expand All @@ -284,7 +287,7 @@ class AdyenDropInModule: NSObject {
}

internal func finish(with error: Error) {
currentComponent?.finalizeIfNeeded(with: false)
actionComponent?.finalizeIfNeeded(with: false)

presenter?.dismiss(animated: true) { [weak self] in
if let componentError = error as? ComponentError {
Expand Down Expand Up @@ -340,13 +343,16 @@ class AdyenDropInModule: NSObject {
}

private func handle(_ action: Action) {
(currentComponent as? DropInComponent)?.handle(action)
actionComponent?.handle(action)
}
}

extension AdyenDropInModule: DropInComponentDelegate {

internal func didSubmit(_ data: PaymentComponentData, for paymentMethod: PaymentMethod, from component: DropInComponent) {
// Hide drawer
presenter?.dismiss(animated: true)

if self.onSubmitCallback != nil {
self.onSubmitCallback?([[
"paymentMethod": data.paymentMethod.encodable.dictionary as Any,
Expand Down

0 comments on commit b17e58b

Please sign in to comment.