flutterpayment

Integration of Flutter with Revolut Payment


using this documentation docs, I am trying to integrate Revoult payment with Flutter.

But I have encountered these errors:

  1. Unresolved reference: RevolutPayEnvironment

  2. Unresolved reference: RevolutPayments

in my "MainActivity.kt"

My Kotlin code:

package com.example.foodbourge_mobile_app

import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES

class MainActivity: FlutterActivity() {
  private val CHANNEL = "samples.flutter.dev/revolut_pay"

  override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    fun getBatteryLevel(): Int {
      val batteryLevel: Int
      if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        val batteryManager = getSystemService(Context.BATTERY_SERVICE) as BatteryManager
        batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
      } else {
        val intent = ContextWrapper(applicationContext).registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
        batteryLevel = intent!!.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
      }

      return batteryLevel
    }
    fun payByRevolut(): Int {
      RevolutPayments.revolutPay.init(
            environment = RevolutPayEnvironment.SANDBOX, // Change to MAIN for production
            merchantPublicKey = "10ccaaa5-9316-44e9-9da1-2e714c3310c0",
            requestShipping = false,
            // customer = Customer(
            //     name = "John Doe",
            //     email = "john@example.com",
            //     phoneNumber = "1234567890",
            //     dateOfBirth = "1990-01-01"
            // )
        )

      return 0
    }
    MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
      call, result ->   
      if (call.method == "getBatteryLevel") {
        val batteryLevel = getBatteryLevel()

        if (batteryLevel != -1) {
          result.success(batteryLevel)
        } else {
          result.error("UNAVAILABLE", "Battery level not available.", null)
        }
      } else {
        result.notImplemented()
      }
    }
  }
}

I have already added :

implementation "com.revolut:revolutpayments:1.0.0"

implementation "com.revolut:revolutpay:2.2"

in my android level build.gradle.

Is the imports I missed?

Please help me.


Solution

  • Use Revolut Flutter SDK, more details on this medium article or on Github repo, here are some highlights.

    RevolutPayment.environment = RevolutEnvironment.[ENV];
    RevolutPayment.merchantPublicKey ="[publicKey]";
    await  RevolutPayment.instance.applySettings();
    

    For Revolut Payments System (for credit cards):

    try {
        await  RevolutPayment.instance.startCardPayment(
            orderId: revolutOrderId,
            //configuration is optional
            configuration: CardPaymentConfiguration(
                email: email,
                billingAddress: CardBillingAddress(
                    streetLine1: line1,
                    streetLine2: line2,
                    city: city,
                    region: region,
                    countryIsoCode: isoCode,
                    postcode: postCode)));
        //success case
    } catch (e) {
        if (e  is  RevolutCardPaymentException) {
            //payment failure case
        } else {
            //general failure case
        }
    }
    

    For Revolut Pay (needs to have Revolut app installed):

    RevolutPayButton(
        orderPublicId: revolutOrderId,
        height: height,
        width: width,
        buttonParams: RevolutPayButtonParams(
            radius: RevolutPayRadius.LARGE,
            size: RevolutPaySize.MEDIUM,
            //lightMode and darkMode are optional
            lightMode: RevolutPayVariant.LIGHT_OUTLINED,
            darkMode: RevolutPayVariant.DARK_OUTLINED),
        onSucceeded: () {
            //success case
        },
        //onFailed is optional
        onFailed: (message) {
            //failure case
        }
    )