Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paypal Vault flow issue #159

Open
RohaanMohsin opened this issue Apr 29, 2024 · 2 comments
Open

Paypal Vault flow issue #159

RohaanMohsin opened this issue Apr 29, 2024 · 2 comments

Comments

@RohaanMohsin
Copy link

RohaanMohsin commented Apr 29, 2024

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
Copy link
Author

@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
Copy link

BunnyBuddy commented Apr 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants