public void OnPaymentDataRequested(PaymentRequest paymentRequest, string token, IPaymentDataCallback callback) { 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 = (p0) => { paymentRequest.Cancel(); } }); }
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(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); paymentRequestDetailsListener = new PaymentRequestDetailsListener { PaymentMethodSelectionRequired = (paymentRequest, recurringMethods, otherMethods, callback) => { PaymentMethodSelectionFragment paymentMethodSelectionFragment = new PaymentMethodSelectionFragmentBuilder() .SetPaymentMethods(new List <PaymentMethod>(otherMethods)) .SetPreferredPaymentMethods(new List <PaymentMethod>(recurringMethods)) .SetPaymentMethodSelectionListener(new PaymentMethodSelectionListener { PaymentMethodSelected = (paymentMethod) => { callback.CompletionWithPaymentMethod(paymentMethod); } }) .Build(); SupportFragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content, paymentMethodSelectionFragment).AddToBackStack(null).CommitAllowingStateLoss(); }, RedirectRequired = (paymentRequest, redirectUrl, returnUriCallback) => { uriCallback = returnUriCallback; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.Build(); customTabsIntent.LaunchUrl(context, Android.Net.Uri.Parse(redirectUrl)); }, // PaymentDetailsRequired = (paymentRequest, inputDetails, callback) => { var paymentMethodType = paymentRequest.PaymentMethod.GetType(); if (PaymentMethod.Type.Card.Equals(paymentMethodType)) { CreditCardFragment creditCardFragment = new CreditCardFragmentBuilder() .SetPaymentMethod(paymentRequest.PaymentMethod) .SetPublicKey(paymentRequest.PublicKey) .SetGenerationtime(paymentRequest.GenerationTime) .SetAmount(paymentRequest.Amount) .SetShopperReference(paymentRequest.ShopperReference) .SetCreditCardInfoListener(new CreditCardInfoListener { CreditCardInfoProvided = (p0) => { callback.CompletionWithPaymentDetails(p0); } }) .Build(); SupportFragmentManager.BeginTransaction() .Replace(Android.Resource.Id.Content, creditCardFragment).AddToBackStack(null) .CommitAllowingStateLoss(); } else if (PaymentMethod.Type.Ideal.Equals(paymentMethodType)) { IssuerSelectionFragment issuerSelectionFragment = new IssuerSelectionFragmentBuilder() .SetPaymentMethod(paymentRequest.PaymentMethod) .SetIssuerSelectionListener(new IssuerSelectionListener { IssuerSelected = (p0) => { IdealPaymentDetails idealPaymentDetails = new IdealPaymentDetails(inputDetails); idealPaymentDetails.FillIssuer(p0); callback.CompletionWithPaymentDetails(idealPaymentDetails); } }) .Build(); SupportFragmentManager.BeginTransaction() .Replace(Android.Resource.Id.Content, issuerSelectionFragment).AddToBackStack(null) .CommitAllowingStateLoss(); } else if (PaymentMethod.Type.SepaDirectDebit.Equals(paymentMethodType)) { SepaDirectDebitFragment sepaDirectDebitFragment = new SepaDirectDebitFragmentBuilder() .SetAmount(paymentRequest.Amount) .SetSEPADirectDebitPaymentDetailsListener(new SEPADirectDebitPaymentDetailsListener { PaymentDetails = (iban, accountHolder) => { SepaDirectDebitPaymentDetails sepaDirectDebitPaymentDetails = new SepaDirectDebitPaymentDetails(inputDetails); sepaDirectDebitPaymentDetails.FillIban(iban); sepaDirectDebitPaymentDetails.FillOwner(accountHolder); callback.CompletionWithPaymentDetails(sepaDirectDebitPaymentDetails); } }) .Build(); SupportFragmentManager.BeginTransaction() .Replace(Android.Resource.Id.Content, sepaDirectDebitFragment).AddToBackStack(null) .CommitAllowingStateLoss(); } else { Toast.MakeText(this, "UI for " + paymentMethodType + " has not been implemented.", ToastLength.Long).Show(); paymentRequest.Cancel(); } } }; context = this; Android.Net.Uri uri = Intent.Data; if (uri == null) { setupInitScreen(); } else { //throw new IllegalStateException("Application was supposed to be declared singleTask"); } }
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"); } }