Skip to content

Latest commit

 

History

History
132 lines (111 loc) · 7.92 KB

FRENCH_MEAL_VOUCHER.md

File metadata and controls

132 lines (111 loc) · 7.92 KB

French meal voucher

On this page, you can find additional configuration for adding French meal vouchers to your integration.

Drop-in

Sessions

The integration works out of the box for sessions implementation. Check out the integration guide here.

Advanced

Follow the Advanced flow integration guide and make sure the Drop-in is configured correctly and supports partial payments.

To configure Drop-in to create and cancel orders, implement the following methods in your DropInService:

Method Explanation
onBalanceCheck(paymentComponentState: PaymentComponentState<*>) Called when the shopper pays with a meal voucher. Make a /paymentMethods/balance request.
onOrderRequest() Called when the meal voucher balance is less than the transaction amount. Make an /orders request with the amount of the total transaction amount.
onOrderCancel(order: Order, shouldUpdatePaymentMethods: Boolean) Called when the shopper cancels the meal voucher transaction. Make an /orders/cancel request.

The following example shows how to configure Drop-in for meal vouchers:

override fun onBalanceCheck(paymentComponentState: PaymentComponentState<*>) {
    // Make a POST /paymentMethods/balance request
    if (isSuccessfulResponse()) {
        val balanceResult = BalanceResult.SERIALIZER.deserialize(jsonResponse)
        val dropInServiceResult = BalanceDropInServiceResult.Balance(balanceResult)
        sendBalanceResult(dropInServiceResult)
    } else {
        val dropInServiceResult = BalanceDropInServiceResult.Error(..)
        sendBalanceResult(dropInServiceResult)
    }
}

override fun onOrderRequest() {
    // Make a POST /orders request
    if (isSuccessfulResponse()) {
        val orderResponse = OrderResponse.SERIALIZER.deserialize(jsonResponse)
        val dropInServiceResult = OrderDropInServiceResult.OrderCreated(orderResponse)
        sendOrderResult(dropInServiceResult)
    } else {
        val dropInServiceResult = OrderDropInServiceResult.Error(..)
        sendOrderResult(dropInServiceResult)
    }
}

override fun onOrderCancel(order: Order, shouldUpdatePaymentMethods: Boolean) {
    val orderJson = OrderRequest.SERIALIZER.serialize(order)
    // Make a POST /orders/cancel request
    if (isSuccessfulResponse()) {
        if (shouldUpdatePaymentMethods) {
            // shouldUpdatePaymentMethods is true when the shopper manually removes their meal vouchers and cancels the order
            // The total reverts to the original amount and you might need to fetch your payment methods and update Drop-in with the new list of payment methods
            val paymentMethods = fetchPaymentMethods() // Fetch the payment methods here
            val dropInServiceResult = DropInServiceResult.Update(paymentMethods, null) // Update the payment methods
        } else {
            // shouldUpdatePaymentMethods is false when Drop-in is closed while the order is in progress
            // If this happens, there is no need to make any further calls.
        }
    } else {
        val dropInServiceResult = DropInServiceResult.Error(..)
        sendResult(dropInServiceResult)
    }
}

Components

Use the following module and component names:

  • To import the module use meal-voucher-fr.
implementation "com.adyen.checkout:meal-voucher-fr:YOUR_VERSION"
  • To launch and show the Component use MealVoucherFRComponent.
val component = MealVoucherFRComponent.PROVIDER.get(
    activity = activity, // or fragment = fragment
    checkoutSession = checkoutSession, // Should be passed only for sessions
    paymentMethod = paymentMethod,
    configuration = checkoutConfiguration,
    componentCallback = callback,
)

Sessions

Make sure to follow the Android Components integration guide for sessions integration here.

Advanced

Make sure to follow the Android Components integration guide for advanced integration here.

The componentCallback which is passed to the MealVoucherFRComponent.PROVIDER requires the following methods to be implemented:

Method Explanation
onRequestOrder() In this method you should make a network call to the /orders endpoint of the Checkout API through your server. This method is called when the user is trying to pay a part of the amount using a partial payment method.
onBalanceCheck(paymentComponentState: PaymentComponentState<*>) In this method you should make a network call to the /paymentMethods/balance endpoint of the Checkout API through your server. This method is called right after the user enters their meal voucher details and submits them.

The following example shows how to implement the MealVoucherFRComponentCallback:

override fun onRequestOrder() {
    // Make a POST /orders request
    if (isSuccessfulResponse()) {
        val orderResponse = OrderResponse.SERIALIZER.deserialize(jsonResponse)
        frenchMealVoucherComponent.resolveOrderResponse(event.order)
    }
}

override fun onBalanceCheck(paymentComponentState: PaymentComponentState<*>) {
    // Make a POST /paymentMethods/balance request
    if (isSuccessfulResponse()) {
        val balanceResult = BalanceResult.SERIALIZER.deserialize(jsonResponse)
        frenchMealVoucherComponent.resolveBalanceResult(event.balanceResult)
    }
}

Optional configurations

CheckoutConfiguration(
    environment = environment,
    clientKey = clientKey,
    ..
) {
    mealVoucherFR {
        setSecurityCodeRequired(true)
    }
}

setSecurityCodeRequired allows you to specify if the Security code field should be hidden from the Component and not requested by the shopper. Note that this might have implications for the transaction.