private static void verifyPayment(Payment payment) { string resultString = "".ToString(); JSONObject jsonObject = new JSONObject(); jsonObject.Put("payload", payment.Payload); string verifystring = (string)jsonObject; Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Content-Type", "application/json; charset=UTF-8"); headers.Add(merchantApiHeaderKeyForApiSecretKey, merchantApiSecretKey); // AsyncHttpClient.Post(merchantServerUrl + VERIFY, headers, verifystring, new HttpResponseCallback { Success = (response) => { Java.Lang.String mString = new Java.Lang.String(response, Charset.ForName("UTF-8")); JSONObject jsonVerifyResponse = new JSONObject((string)mString); Java.Lang.String authResponse = new Java.Lang.String(jsonVerifyResponse.GetString("authResponse")); if (authResponse.EqualsIgnoreCase(payment.GetPaymentStatus().ToString())) { resultString = "Payment is " + payment.GetPaymentStatus().ToString().ToLower() + " and verified."; } else { resultString = "Failed to verify payment."; } }, Failure = (th) => { Toast.MakeText(context, resultString, ToastLength.Long).Show(); } }); }
private void verifyPayment(Payment payment) { JSONObject jsonObject = new JSONObject(); try { jsonObject.Put("payload", payment.Payload); } catch (JSONException e) { Toast.MakeText(this, "Failed to verify payment.", ToastLength.Long).Show(); return; } String verifyString = jsonObject.ToString(); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Content-Type", "application/json; charset=UTF-8"); headers.Add(merchantApiHeaderKeyForApiSecretKey, merchantApiSecretKey); String resultString = ""; AsyncHttpClient.Post(merchantServerUrl + VERIFY, headers, verifyString, new HttpResponseCallback { Success = (response) => { try { JSONObject jsonVerifyResponse = new JSONObject((string)new Java.Lang.String(response, Charset.ForName("UTF-8"))); String authResponse = jsonVerifyResponse.GetString("authResponse"); if (authResponse.Equals(payment.GetPaymentStatus().ToString())) { resultString = "Payment is " + payment.GetPaymentStatus().ToString().ToLower() + " and verified."; } else { resultString = "Failed to verify payment."; } } catch (JSONException e) { resultString = "Failed to verify payment."; } Toast.MakeText(this, resultString, ToastLength.Long).Show(); }, Failure = (e) => { Toast.MakeText(this, resultString, ToastLength.Long).Show(); } }); }
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(); }
private static async void doHttp(SdSource source, HttpMessage msg, __CacheBlock cache, HttpCallback callback) { var encoding = Encoding.GetEncoding(msg.config.encode()); AsyncHttpClient client = new AsyncHttpClient(); client.UserAgent(msg.config.ua()); client.Encoding(msg.config.encode()); foreach (String key in msg.header.Keys) { client.Header(key, msg.header[key]); } string newUrl = null; if (msg.url.IndexOf(" ") >= 0) { newUrl = Uri.EscapeUriString(msg.url); } else { newUrl = msg.url; } client.Url(newUrl); string temp = null; AsyncHttpResponse rsp = null; try { if ("post".Equals(msg.config.method)) { rsp = await client.Post(msg.form); } else { rsp = await client.Get(); } if (rsp.StatusCode == HttpStatusCode.OK) { source.setCookies(rsp.Cookies); temp = rsp.GetString(); if (string.IsNullOrEmpty(rsp.location) == false) { Uri uri = new Uri(msg.url); rsp.location = uri.Scheme + "://" + uri.Host + rsp.location; } } } catch (Exception ex) { Util.log(source, "HTTP", ex.Message); } if (temp == null) { if (cache == null || cache.value == null) { callback(-2, msg, null, rsp.location); } else { callback(1, msg, cache.value, rsp.location); } } else { callback(1, msg, temp, rsp.location); } }
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"); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.activity_main); merchantServerUrl = TextUtils.IsEmpty(merchantServerUrl) ? SERVER_URL : merchantServerUrl; merchantApiSecretKey = TextUtils.IsEmpty(merchantApiSecretKey) ? API_KEY : merchantApiSecretKey; merchantApiHeaderKeyForApiSecretKey = TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey)? API_HEADER_KEY: merchantApiHeaderKeyForApiSecretKey; context = this; SetStatusBarTranslucent(true); Button checkoutButton = (Button)FindViewById(Resource.Id.checkout_button); // checkoutButton.Click += (s, e) => { if (TextUtils.IsEmpty(merchantApiSecretKey) || TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey) || TextUtils.IsEmpty(merchantServerUrl)) { Toast.MakeText(ApplicationContext, "Server parameters have not been configured correctly", ToastLength.Long).Show(); return; } paymentRequest = new PaymentRequest(context, paymentRequestListener); paymentRequest.Start(); }; // paymentRequestListener = new PaymentRequestListener { PaymentDataRequested = (paymentRequest, token, paymentDataCallback) => { 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) => { paymentDataCallback.CompletionWithPaymentData(response); }, Failure = (e) => { Log.Error(TAG, "HTTP Response problem: ", e); System.Diagnostics.Debug.Write("HTTP Response problem: " + e); } }); }, PaymentResult = (paymentRequest, paymentRequestResult) => { if (paymentRequestResult.IsProcessed && (paymentRequestResult.Payment.GetPaymentStatus() == Payment.PaymentStatus.Authorised || paymentRequestResult.Payment.GetPaymentStatus() == Payment.PaymentStatus.Received)) { verifyPayment(paymentRequestResult.Payment); Intent intent = new Intent(context, typeof(SuccessActivity)); StartActivity(intent); Finish(); } else { Intent intent = new Intent(context, typeof(FailureActivity)); StartActivity(intent); Finish(); } } }; }