pikaju / flutter-braintree

Flutter plugin that wraps the native Braintree SDKs. Enables payments with credit cards, PayPal, Google Pay and more.
https://pub.dev/packages/flutter_braintree
MIT License
64 stars 115 forks source link

Paypal Vault flow issue #159

Open RohaanMohsin opened 2 months ago

RohaanMohsin commented 2 months ago

Hello, I am using flutter-braintree version 4.0.0 I am using BraintreePayPalRequest method for integrating Paypal Vault flow but in BraintreePayPalRequest "amount" parameter is required.

According to Documentation, 'amount ' parameter is not required in paypal vault flow Screenshot 2024-04-29 at 1 06 58 PM

in my code, it shows me error "The named parameter 'amount' is required". Screenshot 2024-04-29 at 1 10 49 PM

Note: I am not using Drop-in

So my question is how can i implement paypal Vault flow ? what is the possible way to implement vault flow ? can anyone please help.

Thankyou

RohaanMohsin commented 2 months ago

@BunnyBuddy but there is no Class with name " PayPalVaultRequest " exist in flutter-braintree package version 4.0.0. Can you please guide me little about this. i know if we send amount as null then it automatically goes to vault flow and this is the step where the problem comes when we send amount null.

in BraintreePayPalRequest amount parameter is required otherwise it gives error of missing parameter

BunnyBuddy commented 2 months ago

Okay, I've figured somewhat and it works but you'll have to dig deeper yourself if you want to adjust it further,

Add this in your build.gradle file under /android in flutter_braintree. Because we need this library for PayPalVaultRequest(),

implementation 'com.braintreepayments.api:paypal:4.39.0'

Then, in FlutterBraintreeCustom.java find the method "requestPaypalNonce",

    protected void requestPaypalNonce() {
        Intent intent = getIntent();
        if (intent.getStringExtra("amount") == null) {
            // Vault Flow
            PayPalVaultRequest vaultRequest = new PayPalVaultRequest();
            // vaultRequest.setDisplayName(intent.getStringExtra("displayName"));
            // vaultRequest.setBillingAgreementDescription(intent.getStringExtra("billingAgreementDescription"));
            payPalClient.tokenizePayPalAccount(this, vaultRequest);
        } else {
            // Checkout flow
            PayPalCheckoutRequest checkOutRequest = new PayPalCheckoutRequest(intent.getStringExtra("amount"));
            checkOutRequest.setCurrencyCode(intent.getStringExtra("currencyCode"));
            checkOutRequest.setDisplayName(intent.getStringExtra("displayName"));
            checkOutRequest.setBillingAgreementDescription(intent.getStringExtra("billingAgreementDescription"));
            checkOutRequest.setIntent(PayPalPaymentIntent.AUTHORIZE);
            payPalClient.tokenizePayPalAccount(this, checkOutRequest);
        }
    }

Then, in the file FlutterBraintreeDropIn.java, find the method readPayPalParameters() and match it with below,

   private static void readPayPalParameters(DropInRequest dropInRequest, MethodCall call) {
        HashMap<String, Object> arg = call.argument("paypalRequest");
        if (arg == null) {
            dropInRequest.setPayPalDisabled(true);
            return;
        }
        String amount = (String) arg.get("amount");
//    assert amount != null;
        if (amount == null) {
            PayPalVaultRequest paypalRequest = new PayPalVaultRequest();
            paypalRequest.setBillingAgreementDescription((String) arg.get("billingAgreementDescription"));
            dropInRequest.setPayPalRequest(paypalRequest);
        } else {
            PayPalCheckoutRequest paypalRequest = new PayPalCheckoutRequest(amount);
            paypalRequest.setCurrencyCode((String) arg.get("currencyCode"));
            paypalRequest.setDisplayName((String) arg.get("displayName"));
            paypalRequest.setBillingAgreementDescription((String) arg.get("billingAgreementDescription"));

            dropInRequest.setPayPalRequest(paypalRequest);
        }
    }

And don't forget to add this line at the top of both of these files,

import com.braintreepayments.api.PayPalVaultRequest;

Since I'm not an expert and have never utilised vault, you may or maynot face some problems which you can figure out by reading the docummentation given in the links below.

If you face any issues then find the docummentation for DropIn, https://developer.paypal.com/braintree/docs/guides/paypal/vault/android/v3# https://javadoc.io/doc/com.braintreepayments.api/paypal/4.12.0/index.html https://www.javadoc.io/doc/com.braintreepayments.api/drop-in/6.0.0-beta1/index.html