Installments
To use installments please add new library to gradle file: payment-add-card-module.
UI can be customized using Global class that extends DefaultStyleConfiguration (please check global UI guideline).
Before implementation
You should also have implemented (on your backend):
- Transaction API Call (this card should be takend after OCR, and after merchant backend received completed as transaction status with information about
proposalId
) - Retrieve Proposal API Call (this call have an information regarding possible installments - needed for Mobile SDK)
- Send Proposal API Call (send selected proposal - this should be called after Mobile Installment flow finishes)
Installments can be taken (and displayed) only after OCR was processed and works for card Payment.
Implementation flow
In your implementation of PaymentMethodActions please override method: override fun provideInstallments(callback: InstallmentCallback)
This method is responsible for retrieving installments from merchant API.
val disposable = installmentRepository.getInstallmentOption(persistenceRepository.proposalId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
if (it.installmentDecision != null) {
//merchant could display an information regarding this flow
println("Installment previously taken: $it")
return@subscribe
}
val installmentList: ArrayList<InstallmentOption> = ArrayList()
it.installmentOptions.forEach { item ->
installmentList.add(InstallmentOption.Builder()
.withId(item.id)
.withFirstInstallments(item.firstInstallmentAmount ?: 0)
.withNumberOfInstallments(item.numberOfInstallments ?: 0)
.withTotalValue(item.totalAmountDue)
.withAnnualPercentageRate(item.annualPercentageRate)
.withInstallmentAmount(item.installmentAmount ?: 0)
.withInstallmentFeeAmount(item.installmentFeeAmount)
.withInterestRate(item.interestRate)
.build())
}
val installment: Installment = Installment.Builder()
.withCurrency(it.currencyCode)
.withProposalId(persistenceRepository.proposalId)
.withInstallmentType(it.installmentOptionFormat)
.withInstallmentOptionList(installmentList)
.withMaxNumberOfInstallments(it.maxNumberOfInstallments ?: 0)
.withMinNumberOfInstallments(it.minNumberOfInstallments ?: 0)
.build()
callback.onFetched(installment)
}, {
println("Error during fetching installments: $it")
})
For creating a model we are providing:
com.payu.android.front.sdk.payment_library_core.external.model.Installment.Builder
com.payu.android.front.sdk.payment_library_core.external.model.InstallmentOption.Builder
To trigger installment flow please call:
**com.payu.android.front.sdk.payment_installments.mastercard.offer.view.OfferInstallmentsActivity.startForResult(activity: Activity)
Data will be returned in override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {...}
Returned object:
//type: VARYING_NUMBER_OF_OPTIONS or VARYING_NUMBER_OF_INSTALLMENTS
SelectedInstallment(val id: String, val installmentType: String, val proposalId: String?)
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
...
OfferInstallmentsActivity.INSTALLMENT_REQUEST_CODE -> {
val selectedInstallment: SelectedInstallment = data.getParcelableExtra(OfferInstallmentsActivity.INSTALLMENT_KEY)
val installmentSelected: InstallmentSelected =
if (selectedInstallment.installmentType == InstallmentType.OPTIONS.toString())
InstallmentSelected(selectedInstallment.id)
else InstallmentSelected(numberOfInstallments = selectedInstallment.id.toInt())
//Make a call to request an installment from backend
viewModel.requestInstallment(installmentSelected, selectedInstallment.proposalId!!)
Toast.makeText(this, "Installment finished", Toast.LENGTH_SHORT).show()
}
}
}
In case when user would like to cancel an installment we will send RESULT_CANCELED and close an installment flow.
Default Style of Installments Screen
- Choosing Installments
- Choosing Number of Installments
- Choosing Installments Option