public void onPaymentRequested(PaymentSetupRequest paymentSetupRequest)
        {
            merchantServerUrl    = TextUtils.IsEmpty(merchantServerUrl) ? SERVER_URL : merchantServerUrl;
            merchantApiSecretKey = TextUtils.IsEmpty(merchantApiSecretKey) ? API_KEY : merchantApiSecretKey;
            merchantApiHeaderKeyForApiSecretKey = TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey)
                    ? API_HEADER_KEY
                    : merchantApiHeaderKeyForApiSecretKey;

            if (TextUtils.IsEmpty(merchantApiSecretKey) ||
                TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey) ||
                TextUtils.IsEmpty(merchantServerUrl))
            {
                //Toast.makeText(getApplicationContext(), "Server parameters have not been configured correctly", Toast.LENGTH_SHORT).show();
                return;
            }

            this.paymentSetupRequest = paymentSetupRequest;
            if (paymentRequest != null)
            {
                paymentRequest.Cancel();
            }
            paymentRequest = new PaymentRequest(this, this, paymentRequestDetailsListener);
            paymentRequest.Start();
        }
        public void onPaymentRequested(PaymentSetupRequest paymentSetupRequest)
        {
            Log.Debug(TAG, "onPaymentRequested");
            merchantServerUrl    = TextUtils.IsEmpty(merchantServerUrl) ? SERVER_URL : merchantServerUrl;
            merchantApiSecretKey = TextUtils.IsEmpty(merchantApiSecretKey) ? API_KEY : merchantApiSecretKey;
            merchantApiHeaderKeyForApiSecretKey = TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey)
                    ? API_HEADER_KEY
                    : merchantApiHeaderKeyForApiSecretKey;

            if (TextUtils.IsEmpty(merchantApiSecretKey) ||
                TextUtils.IsEmpty(merchantApiHeaderKeyForApiSecretKey) ||
                TextUtils.IsEmpty(merchantServerUrl))
            {
                Toast.MakeText(ApplicationContext, "Server parameters have not been configured correctly", ToastLength.Long).Show();
                return;
            }
            this.paymentSetupRequest = paymentSetupRequest;
            if (paymentRequest != null)
            {
                paymentRequest.Cancel();
            }
            paymentRequest = new PaymentRequest(this, paymentRequestListener);
            paymentRequest.Start();
        }
Beispiel #3
0
        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();
                    }
                }
            };
        }