Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.processout.example.ui.screen.nativeapm.NativeApmUiState.*
import com.processout.sdk.core.onFailure
import com.processout.sdk.core.onSuccess
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Button
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.*
import com.processout.sdk.ui.napm.PONativeAlternativePaymentLauncher
import com.processout.sdk.ui.napm.delegate.PONativeAlternativePaymentDelegate
import com.processout.sdk.ui.nativeapm.PONativeAlternativePaymentMethodConfiguration
Expand Down Expand Up @@ -73,18 +73,26 @@ class NativeApmFragment : BaseFragment<FragmentNativeApmBinding>(
}

private fun setOnClickListeners() {
binding.launchNativeApmButton.setOnClickListener {
onSubmitClick(launchCompose = false)
binding.buttonAuthorizeLegacy.setOnClickListener {
onSubmitClick(launchCompose = false, tokenize = false)
}
binding.launchNativeApmComposeButton.setOnClickListener {
onSubmitClick(launchCompose = true)
binding.buttonAuthorizeCompose.setOnClickListener {
onSubmitClick(launchCompose = true, tokenize = false)
}
binding.buttonTokenizeCompose.setOnClickListener {
onSubmitClick(launchCompose = true, tokenize = true)
}
}

private fun onSubmitClick(launchCompose: Boolean) {
private fun onSubmitClick(launchCompose: Boolean, tokenize: Boolean) {
val amount = binding.amountInput.text.toString()
val currency = binding.currencyInput.text.toString()
viewModel.createInvoice(amount, currency, launchCompose)
viewModel.createInvoice(
amount = amount,
currency = currency,
launchCompose = launchCompose,
tokenize = tokenize
)
}

private fun handle(uiState: NativeApmUiState) {
Expand All @@ -98,13 +106,36 @@ class NativeApmFragment : BaseFragment<FragmentNativeApmBinding>(

private fun launch(uiModel: NativeApmUiModel) {
if (uiModel.launchCompose) {
launcherCompose.launch(
PONativeAlternativePaymentConfiguration(
invoiceId = uiModel.invoiceId,
gatewayConfigurationId = uiModel.gatewayConfigurationId,
submitButton = Button()
if (uiModel.tokenize) {
launcherCompose.launch(
PONativeAlternativePaymentConfiguration(
flow = Flow.Tokenization(
customerId = uiModel.customerId,
customerTokenId = uiModel.customerTokenId,
gatewayConfigurationId = uiModel.gatewayConfigurationId
),
cancelButton = CancelButton(),
paymentConfirmation = PaymentConfirmationConfiguration(
confirmButton = Button(),
cancelButton = CancelButton(disabledForSeconds = 3)
)
)
)
)
} else {
launcherCompose.launch(
PONativeAlternativePaymentConfiguration(
flow = Flow.Authorization(
invoiceId = uiModel.invoiceId,
gatewayConfigurationId = uiModel.gatewayConfigurationId
),
cancelButton = CancelButton(),
paymentConfirmation = PaymentConfirmationConfiguration(
confirmButton = Button(),
cancelButton = CancelButton(disabledForSeconds = 3)
)
)
)
}
} else {
launcher.launch(
PONativeAlternativePaymentMethodConfiguration(
Expand All @@ -128,8 +159,9 @@ class NativeApmFragment : BaseFragment<FragmentNativeApmBinding>(
with(binding) {
amountInput.isEnabled = isEnabled
currencyInput.isEnabled = isEnabled
launchNativeApmButton.isClickable = isEnabled
launchNativeApmComposeButton.isClickable = isEnabled
buttonAuthorizeLegacy.isClickable = isEnabled
buttonAuthorizeCompose.isClickable = isEnabled
buttonTokenizeCompose.isClickable = isEnabled
amountInput.clearFocus()
currencyInput.clearFocus()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ sealed class NativeApmUiState {
data class NativeApmUiModel(
val invoiceId: String,
val gatewayConfigurationId: String,
val launchCompose: Boolean
val customerId: String,
val customerTokenId: String,
val launchCompose: Boolean,
val tokenize: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import androidx.lifecycle.viewModelScope
import com.processout.example.ui.screen.nativeapm.NativeApmUiState.*
import com.processout.sdk.api.ProcessOut
import com.processout.sdk.api.model.request.POCreateCustomerRequest
import com.processout.sdk.api.model.request.POCreateCustomerTokenRequest
import com.processout.sdk.api.model.request.POCreateCustomerTokenRequestBody
import com.processout.sdk.api.model.request.POCreateInvoiceRequest
import com.processout.sdk.api.model.response.POCustomer
import com.processout.sdk.api.model.response.POCustomerToken
import com.processout.sdk.api.service.POCustomerTokensService
import com.processout.sdk.api.service.POInvoicesService
import com.processout.sdk.core.getOrNull
Expand Down Expand Up @@ -44,23 +47,29 @@ class NativeApmViewModel(
fun createInvoice(
amount: String,
currency: String,
launchCompose: Boolean
launchCompose: Boolean,
tokenize: Boolean
) {
_uiState.value = Submitting
viewModelScope.launch {
val customerId = createCustomer()?.id ?: String()
val customerTokenId = createCustomerToken(customerId)?.id ?: String()
val request = POCreateInvoiceRequest(
name = UUID.randomUUID().toString(),
amount = amount,
currency = currency,
customerId = createCustomer()?.id
customerId = customerId
)
invoices.createInvoice(request)
.onSuccess { invoice ->
_uiState.value = Submitted(
NativeApmUiModel(
invoiceId = invoice.id,
gatewayConfigurationId = gatewayConfigurationId,
launchCompose = launchCompose
customerId = customerId,
customerTokenId = customerTokenId,
launchCompose = launchCompose,
tokenize = tokenize
)
)
}.onFailure { _uiState.value = Failure(it) }
Expand All @@ -76,6 +85,14 @@ class NativeApmViewModel(
)
).getOrNull()

private suspend fun createCustomerToken(customerId: String): POCustomerToken? =
customerTokens.createCustomerToken(
POCreateCustomerTokenRequest(
customerId = customerId,
body = POCreateCustomerTokenRequestBody()
)
).getOrNull()

fun onLaunched() {
_uiState.value = Launched
}
Expand Down
70 changes: 40 additions & 30 deletions example/src/main/res/layout/fragment_native_apm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:defaultFocusHighlightEnabled="false"
android:fillViewport="true"
android:isScrollContainer="true"
app:layout_constraintBottom_toTopOf="@id/footer_divider"
app:layout_constraintBottom_toTopOf="@id/buttons"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down Expand Up @@ -76,38 +76,48 @@
</LinearLayout>
</androidx.core.widget.NestedScrollView>

<View
android:id="@+id/footer_divider"
android:layout_width="match_parent"
android:layout_height="@dimen/po_borderWidth"
android:layout_marginBottom="@dimen/button_marginVertical"
android:background="@color/po_border_subtle"
app:layout_constraintBottom_toTopOf="@id/launch_native_apm_button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<Button
android:id="@+id/launch_native_apm_button"
<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/button_space_vertical"
android:text="@string/launch_native_apm"
app:layout_constraintBottom_toTopOf="@id/launch_native_apm_compose_button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<Button
android:id="@+id/launch_native_apm_compose_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/button_marginVertical"
android:text="@string/launch_native_apm_compose"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
app:layout_constraintRight_toRightOf="parent">

<View
android:id="@+id/footer_divider"
android:layout_width="match_parent"
android:layout_height="@dimen/po_borderWidth"
android:layout_marginBottom="@dimen/button_marginVertical"
android:background="@color/po_border_subtle" />

<Button
android:id="@+id/button_authorize_legacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/button_space_vertical"
android:text="Authorize (Legacy)" />

<Button
android:id="@+id/button_authorize_compose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/button_marginVertical"
android:text="Authorize (Compose)" />

<Button
android:id="@+id/button_tokenize_compose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginBottom="@dimen/button_marginVertical"
android:text="Tokenize (Compose)" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 0 additions & 2 deletions example/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

<string name="dynamic_checkout" translatable="false">Dynamic Checkout (Beta)</string>
<string name="native_apm" translatable="false">Native Alternative Payment</string>
<string name="launch_native_apm" translatable="false">Launch Native APM</string>
<string name="launch_native_apm_compose" translatable="false">Launch Native APM (Compose)</string>
<string name="authorize_invoice" translatable="false">Authorize Invoice</string>
<string name="invoice_details" translatable="false">Invoice Details</string>
<string name="amount" translatable="false">Amount</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.processout.sdk.ui.core.theme.ProcessOutTheme
import com.processout.sdk.ui.googlepay.POGooglePayCardTokenizationLauncher
import com.processout.sdk.ui.napm.NativeAlternativePaymentViewModel
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Flow
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.PaymentConfirmationConfiguration
import com.processout.sdk.ui.savedpaymentmethods.POSavedPaymentMethodsLauncher
import com.processout.sdk.ui.savedpaymentmethods.delegate.POSavedPaymentMethodsDelegate
Expand Down Expand Up @@ -128,8 +129,10 @@ internal class DynamicCheckoutActivity : BaseTransparentPortraitActivity() {
private fun nativeAlternativePaymentConfiguration(): PONativeAlternativePaymentConfiguration {
val paymentConfirmation = configuration.alternativePayment.paymentConfirmation
return PONativeAlternativePaymentConfiguration(
invoiceId = configuration.invoiceRequest.invoiceId,
gatewayConfigurationId = String(),
flow = Flow.Authorization(
invoiceId = configuration.invoiceRequest.invoiceId,
gatewayConfigurationId = String()
),
submitButton = configuration.submitButton.map(),
cancelButton = configuration.cancelButton?.map(),
paymentConfirmation = PaymentConfirmationConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.processout.sdk.ui.checkout.delegate.*
import com.processout.sdk.ui.checkout.delegate.PODynamicCheckoutEvent.*
import com.processout.sdk.ui.napm.*
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.*
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Flow
import com.processout.sdk.ui.napm.delegate.PONativeAlternativePaymentEvent
import com.processout.sdk.ui.savedpaymentmethods.POSavedPaymentMethodsConfiguration
import com.processout.sdk.ui.shared.extension.orElse
Expand Down Expand Up @@ -531,8 +532,10 @@ internal class DynamicCheckoutInteractor(
gatewayConfigurationId: String,
configuration: AlternativePaymentConfiguration
) = copy(
invoiceId = invoiceId,
gatewayConfigurationId = gatewayConfigurationId,
flow = Flow.Authorization(
invoiceId = invoiceId,
gatewayConfigurationId = gatewayConfigurationId
),
paymentConfirmation = paymentConfirmation.apply(configuration.paymentConfirmation),
barcode = configuration.barcode,
inlineSingleSelectValuesLimit = configuration.inlineSingleSelectValuesLimit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.processout.sdk.api.dispatcher.PODefaultEventDispatchers
import com.processout.sdk.core.*
import com.processout.sdk.core.POUnit
import com.processout.sdk.core.ProcessOutActivityResult
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.core.toActivityResult
import com.processout.sdk.ui.base.BaseBottomSheetDialogFragment
import com.processout.sdk.ui.core.component.POIme.isImeVisibleAsState
import com.processout.sdk.ui.core.theme.ProcessOutTheme
Expand All @@ -29,7 +32,7 @@ import com.processout.sdk.ui.napm.NativeAlternativePaymentEvent.PermissionReques
import com.processout.sdk.ui.napm.NativeAlternativePaymentScreen.AnimationDurationMillis
import com.processout.sdk.ui.napm.NativeAlternativePaymentSideEffect.PermissionRequest
import com.processout.sdk.ui.napm.NativeAlternativePaymentViewModelState.Capture
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Button
import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Flow
import com.processout.sdk.ui.shared.component.screenModeAsState
import com.processout.sdk.ui.shared.extension.collectImmediately
import com.processout.sdk.ui.shared.extension.dpToPx
Expand All @@ -52,9 +55,10 @@ internal class NativeAlternativePaymentBottomSheet : BaseBottomSheetDialogFragme
NativeAlternativePaymentViewModel.Factory(
app = requireActivity().application,
configuration = configuration ?: PONativeAlternativePaymentConfiguration(
invoiceId = String(),
gatewayConfigurationId = String(),
submitButton = Button()
flow = Flow.Authorization(
invoiceId = String(),
gatewayConfigurationId = String()
)
),
legacyEventDispatcher = PODefaultEventDispatchers.defaultNativeAlternativePaymentMethod
)
Expand All @@ -69,17 +73,6 @@ internal class NativeAlternativePaymentBottomSheet : BaseBottomSheetDialogFragme
super.onAttach(context)
@Suppress("DEPRECATION")
configuration = arguments?.getParcelable(EXTRA_CONFIGURATION)
configuration?.run {
if (invoiceId.isBlank() || gatewayConfigurationId.isBlank()) {
dismiss(
ProcessOutResult.Failure(
code = POFailure.Code.Generic(),
message = "Invalid configuration: 'invoiceId' and 'gatewayConfigurationId' is required."
)
)
return
}
}
viewModel.start()
}

Expand Down
Loading