Git Product home page Git Product logo

Comments (11)

lkorth avatar lkorth commented on May 28, 2024
  1. Does your fragment setup Braintree?
  2. Are you adding your Fragment as a listener?
  3. Are you receiving the call to Activity#onActivityResult in your Activity or Fragment?
  4. If you're expecting Fragment#onActivityResult to be called, are you calling super#onActivityResult in your Activity if you are overriding the method?
  5. Is the result successful in onActivityResult?
  6. Are you registering any error listeners with Braintree? If so are you receiving errors?

from braintree_android.

pawarlalit29 avatar pawarlalit29 commented on May 28, 2024

receiving the call to onActivityResult in Fragment?

from braintree_android.

lkorth avatar lkorth commented on May 28, 2024

Yes, it is possible to receive [onActivityResult in a Fragment](http://developer.android.com/reference/android/app/Fragment.html#onActivityResult%28int, int, android.content.Intent%29).

In order to figure out the issue you are having, we'll need more information such as the questions I asked above, or if you can reproduce it in a simple case and share it, we're happy to take a look. Is this happening for credit cards or other payment methods? You may also want to make sure you're handling the result in onActivityResult, if you are not, you will not receive callbacks for Venmo or PayPal.

You can also contact [email protected].

from braintree_android.

pawarlalit29 avatar pawarlalit29 commented on May 28, 2024

but onPaymentMethodNonce method not getting called in fragment ,in activity is still working but not in fragment

from braintree_android.

lkorth avatar lkorth commented on May 28, 2024

Is this for credit card tokenization or other payment methods?

from braintree_android.

pawarlalit29 avatar pawarlalit29 commented on May 28, 2024

credit card tokenization its working fine on fragment its only problem in Paypal payment method

from braintree_android.

lkorth avatar lkorth commented on May 28, 2024

Are you calling Braintree#finishPayWithPayPal in Activity#onActivityResult?

Do you have an example of your Activity and Fragment that you can share? It's unclear how your code is setup and in order to debug further I'll need more information. You can also step through it with a debugger to see what is happening.

from braintree_android.

pawarlalit29 avatar pawarlalit29 commented on May 28, 2024
public class Frag_Paypal extends Fragment implements PaymentMethodNonceListener {

    View view;
    private Braintree mBraintree;
    private Button mPaymentButton;
    String client_token ;

    private static int PayPal_Request_Code = 11876;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(
                R.layout.fragment_paypal, container, false);


        mPaymentButton = (Button) view.findViewById(R.id.btn_donate);
        setData();

        mPaymentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callPayPal();
            }
        });

        return view;
    }

    public void callPayPal(){
        mBraintree.startPayWithPayPal(getActivity(), PayPal_Request_Code);
    }

    public void setData(){

        Bundle b = getArguments();
        HashMap<String,String> obj;

        if (!b.getSerializable(AppConstant.DONATE_DETAIL).equals(null)) {
            obj = (HashMap<String, String>) b
                    .getSerializable(AppConstant.DONATE_DETAIL);
            client_token = obj.get(BraintreePaymentActivity.EXTRA_CLIENT_TOKEN);

            mBraintree = Braintree.getInstance(getActivity(), client_token);
            mBraintree.addListener(this);
        }
    }


    @Override
    public void onPaymentMethodNonce(String paymentMethodNonce) {
        Log.i("paymentListner--------", paymentMethodNonce);

        Toast.makeText(getActivity(),"paymentMethodNonce"+paymentMethodNonce,Toast.LENGTH_LONG).show();
           /* getActivity().setResult(getActivity().RESULT_OK, new Intent()
                    .putExtra(BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE, paymentMethodNonce));*/

    paymentAlert(paymentMethodNonce);
        //finish();
    }

    @Override
    public void onActivityResult(int requestCode, int responseCode, Intent data) {
        Log.i("inonactivity","asfsdfdf");
        /*if (requestCode == PaymentButton.REQUEST_CODE) {
            mPaymentButton.onActivityResult(requestCode, responseCode, data);
        }*/

        if (requestCode == PayPal_Request_Code && responseCode == Activity.RESULT_OK) {
            if(PayPalHelper.isPayPalIntent(data)) {
                mBraintree.finishPayWithPayPal(getActivity(), responseCode, data);
            } else {
                mBraintree.finishPayWithVenmo(responseCode, data);
            }
        }
    }




    public void paymentAlert(String str_msg){

        AlertDialog.Builder  _builder = new AlertDialog.Builder(getActivity(),R.style.MyAlertDialogStyle);

        _builder.setTitle("Donation")
                .setMessage(str_msg)
                .setNegativeButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();

                    }
                });

        final AlertDialog dialog = _builder.create();
        dialog.show();

    }

}

// this is my fragment onPaymentMethodNonce method not getting called

from braintree_android.

lkorth avatar lkorth commented on May 28, 2024

The issue with this is mBraintree.startPayWithPayPal(getActivity(), PayPal_Request_Code); is calling Activity#startActivityForResult and not Fragment#startActivityForResult. Your Fragment will never receive a call to Fragment#onActivityResult, you will need to override Activity#onActivityResult and either call Braintree#finishPayWithPayPal or call a method in your Fragment with the parameters.

from braintree_android.

dineshlt avatar dineshlt commented on May 28, 2024

Hi @lkorth
I have implemented braintree sdk (Express Checkout) in my app.
OnPaymentMethodNonce callback method not getting called in fragment

I have added my paypal Activity and fragment codes below, Kindly check and do the needful.
Thanks...

public class PaymentActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_out);
        Init();
    }

    private void Init() {

	FrameLayout frameLayout = findViewById(R.id.frame);
          
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            PaymentFragment checkoutLoginFragment = new PaymentFragment();
            fragmentTransaction.replace(R.id.frame, checkoutLoginFragment);
            fragmentTransaction.commit();
       
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        for (Fragment fragment : getSupportFragmentManager().getFragments()) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }
}
----------------------------------------------------------------------------------------------------------------

public class PaymentFragment extends Fragment implements PaymentMethodNonceListener {

    private Braintree mBraintree;
    private Button mPaymentButton;
    String mClientToken ;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_paypal, container, false);
        mPaymentButton = (Button) view.findViewById(R.id.btn_donate);
                  try {
                        if(getActivity()!=null){
                            mBraintreeFragment = BraintreeFragment.newInstance(getActivity(),mClientToken);
                        }
                    } catch (InvalidArgumentException e) {
                        e.printStackTrace(); 
                    }

        mPaymentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PayPalExpressCheckout();
            }
        });
        return view;
    }

public void PayPalExpressCheckout(){
        PostalAddress address=new PostalAddress()
				.streetAddress(“13th street”)
				.locality(“SanMarkam”) 
				.region(“kelongudi”)
				.recipientName(“John Mark”)
				.countryCodeAlpha2(Arabia);
        PayPalRequest request = new PayPalRequest("1")
                			.currencyCode("USD")
                			.shippingAddressRequired(true)
                			.shippingAddressOverride(address)
                			.intent(PayPalRequest.INTENT_AUTHORIZE);
        PayPal.requestOneTimePayment(mBraintreeFragment, request);
    }
}

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }


@Override
   public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        String nonce = paymentMethodNonce.getNonce();

        if (paymentMethodNonce instanceof PayPalAccountNonce) {
            PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce)paymentMethodNonce;

            // Access additional information
            String email = payPalAccountNonce.getEmail();
            String firstName = payPalAccountNonce.getFirstName();
            String lastName = payPalAccountNonce.getLastName();
            String phone = payPalAccountNonce.getPhone();

            // See PostalAddress.java for details
            PostalAddress billingAddress = payPalAccountNonce.getBillingAddress();
            PostalAddress shippingAddress = payPalAccountNonce.getShippingAddress();
        }
    }

}

from braintree_android.

williamli avatar williamli commented on May 28, 2024

I am having a similar problem with @dineshlt

I have a MainActivity in my app and then a PaymentFragment.

Inside the PaymentFragment, I have

mBraintreeFragment = BraintreeFragment.newInstance(getActivity(), clientToken);

and the Fragment's PaymentMethodNonceListener is not called since the braintree fragment is attached to the activity instead and there is no way for me to create a BraintreeFragment from within my PaymentFragment.

from braintree_android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.