public override void OnAttach(Context context)
 {
     base.OnAttach(context);
     this.paymentRequestListener = (PaymentRequestListener)context;
 }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            string resultString = "".ToString();

            paymentRequestListener = new PaymentRequestListener
            {
                PaymentDataRequested = (request, token, callback) =>
                {
                    if (paymentRequest != request)
                    {
                        Log.Debug(TAG, "onPaymentDataRequested(): This is not the payment request that we created.");
                        return;
                    }

                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Content-Type", "application/json; charset=UTF-8");
                    headers.Add(merchantApiHeaderKeyForApiSecretKey, merchantApiSecretKey);

                    AsyncHttpClient.Post(merchantServerUrl + SETUP, headers, getSetupDataString(token), new HttpResponseCallback
                    {
                        Success = (response) =>
                        {
                            callback.CompletionWithPaymentData(response);
                        },
                        Failure = (e) =>
                        {
                            paymentRequest.Cancel();
                        }
                    });
                },
                PaymentResult = (request, paymentResult) =>
                {
                    if (paymentRequest != request)
                    {
                        Log.Debug(TAG, "onPaymentResult(): This is not the payment request that we created.");
                        return;
                    }
                    string MresultString;
                    if (paymentResult.IsProcessed)
                    {
                        MresultString = paymentResult.Payment.GetPaymentStatus().ToString();
                        verifyPayment(paymentResult.Payment);
                    }
                    else
                    {
                        MresultString = paymentResult.Error.ToString();
                    }

                    Intent intent = new Intent(ApplicationContext, typeof(PaymentResultActivity));
                    intent.PutExtra("Result", MresultString);
                    intent.AddFlags(ActivityFlags.ClearTop);
                    intent.AddFlags(ActivityFlags.NewTask);
                    StartActivity(intent);
                    Finish(); // continuing these lines after add verifyPayment method
                }
            };
            PaymentDataEntryFragment paymentDataEntryFragment = new PaymentDataEntryFragment();

            SupportFragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content,
                                                              paymentDataEntryFragment).CommitAllowingStateLoss();
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            paymentRequestDetailsListener = new PaymentRequestDetailsListener
            {
                PaymentMethodSelectionRequired = (paymentRequest, recurringMethods, otherMethods, callback) =>
                {
                    paymentMethodCallback = callback;
                    preferredPaymentMethods.Clear();
                    preferredPaymentMethods.AddRange(recurringMethods);
                    availablePaymentMethods.Clear();
                    availablePaymentMethods.AddRange(otherMethods);
                    PaymentMethodSelectionFragment paymentMethodSelectionFragment = new PaymentMethodSelectionFragment();
                    SupportFragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content, paymentMethodSelectionFragment).AddToBackStack(null).CommitAllowingStateLoss();
                },
                RedirectRequired = (paymentRequest, redirectUrl, returnUriCallback) =>
                {
                    Log.Debug(TAG, "paymentRequestDetailsListener.onRedirectRequired(): " + redirectUrl);
                    uriCallback = returnUriCallback;
                    CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
                    CustomTabsIntent         customTabsIntent = builder.Build();
                    customTabsIntent.LaunchUrl(context, Android.Net.Uri.Parse(redirectUrl));
                },
                PaymentDetailsRequired = (paymentRequest, inputDetails, callback) =>
                {
                    Log.Debug(TAG, "paymentRequestDetailsListener.onPaymentDetailsRequired()");
                    String paymentMethodType = paymentRequest.PaymentMethod.GetType();

                    if (PaymentMethod.Type.Card.Equals(paymentMethodType))
                    {
                        CreditCardFragment creditCardFragment = new CreditCardFragment();
                        Bundle             bundle             = new Bundle();
                        //ONE CLICK CHECK
                        bool isOneClick = InputDetailsUtil.ContainsKey(inputDetails, "cardDetails.cvc");
                        if (isOneClick)
                        {
                            bundle.PutBoolean("oneClick", true);
                        }
                        creditCardFragment.setCreditCardInfoListener(new CreditCardInfoListener
                        {
                            CreditCardInfoProvided = (creditCardInfo) =>
                            {
                                if (isOneClick)
                                {
                                    CVCOnlyPaymentDetails cvcOnlyPaymentDetails = new CVCOnlyPaymentDetails(inputDetails);
                                    cvcOnlyPaymentDetails.FillCvc(creditCardInfo);
                                    callback.CompletionWithPaymentDetails(cvcOnlyPaymentDetails);
                                }
                                else
                                {
                                    CreditCardPaymentDetails creditCardPaymentDetails = new CreditCardPaymentDetails(inputDetails);
                                    creditCardPaymentDetails.FillCardToken(creditCardInfo);
                                    callback.CompletionWithPaymentDetails(creditCardPaymentDetails);
                                }
                            }
                        });
                        bundle.PutString("public_key", paymentRequest.PublicKey);
                        bundle.PutString("generation_time", paymentRequest.GenerationTime);
                        creditCardFragment.Arguments = bundle;

                        SupportFragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content,
                                                                          creditCardFragment).AddToBackStack(null).CommitAllowingStateLoss();
                    }
                    else if (PaymentMethod.Type.Ideal.Equals(paymentMethodType))
                    {
                        AlertDialog.Builder     alertDialog       = new AlertDialog.Builder(this);
                        List <InputDetail.Item> issuers           = InputDetailsUtil.GetInputDetail(inputDetails, "idealIssuer").Items as List <InputDetail.Item>;
                        IssuerListAdapter       issuerListAdapter = new IssuerListAdapter(this, issuers);
                        alertDialog.SetSingleChoiceItems(issuerListAdapter, -1, new OnClickListener
                        {
                            Click = (dialogInterface, i) =>
                            {
                                IdealPaymentDetails idealPaymentDetails = new IdealPaymentDetails(inputDetails);
                                idealPaymentDetails.FillIssuer(issuers[i]);
                                dialogInterface.Dismiss();
                                callback.CompletionWithPaymentDetails(idealPaymentDetails);
                            }
                        });
                        alertDialog.Show();
                    }
                    else
                    {
                        String message = "UI for " + paymentMethodType + " has not been implemented.";
                        Log.Warn(TAG, message);
                        Toast.MakeText(this, message, ToastLength.Long).Show();
                        paymentRequest.Cancel();
                    }
                }
            };
            paymentRequestListener = new PaymentRequestListener
            {
                PaymentDataRequested = (paymentRequest, token, callback) =>
                {
                    Log.Debug(TAG, "paymentRequestListener.onPaymentDataRequested()");
                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Content-Type", "application/json; charset=UTF-8");
                    headers.Add(merchantApiHeaderKeyForApiSecretKey, merchantApiSecretKey);
                    AsyncHttpClient.Post(merchantServerUrl + SETUP, headers, getSetupDataString(token), new HttpResponseCallback
                    {
                        Success = (response) =>
                        {
                            callback.CompletionWithPaymentData(response);
                        },
                        Failure = (e) =>
                        {
                            Log.Error(TAG, "HTTP Response problem: ", e);
                            paymentRequest.Cancel();
                        }
                    });
                },
                PaymentResult = (paymentRequest, paymentResult) =>
                {
                    Log.Debug(TAG, "paymentRequestListener.onPaymentResult()");
                    String resultString;
                    if (paymentResult.IsProcessed)
                    {
                        resultString = paymentResult.Payment.GetPaymentStatus().ToString();
                        verifyPayment(paymentResult.Payment);
                    }
                    else
                    {
                        resultString = paymentResult.Error.ToString();
                    }

                    Intent intent = new Intent(ApplicationContext, typeof(PaymentResultActivity));
                    intent.PutExtra("Result", resultString);
                    intent.AddFlags(ActivityFlags.ClearTop);
                    intent.AddFlags(ActivityFlags.NewTask);
                    StartActivity(intent);
                    Finish();
                }
            };
            Log.Debug(TAG, "onCreate()");
            context = this;
            Android.Net.Uri uri = Intent.Data;
            if (uri == null)
            {
                setupInitScreen();
            }
            else
            {
                throw new Java.Lang.IllegalStateException("Application was supposed to be declared singleTask");
            }
        }