Пример #1
0
        private void StartTransaction()
        {
            if (!_registerClient.IsRegisterInstalled)
            {
                new Android.Support.V7.App.AlertDialog.Builder(this)
                .SetTitle(Resource.String.install_register_title)
                .SetMessage(Resource.String.install_register_message)
                .SetPositiveButton(Resource.String.install_register_confirm,
                                   (sender, e) => _registerClient.OpenRegisterPlayStoreListing())
                .SetNegativeButton(Android.Resource.String.Cancel,
                                   (sender, e) => { })
                .Show();
                return;
            }

            var amountString = _transactionAmountEditText.Text;
            var amount       = string.IsNullOrWhiteSpace(amountString) ? 0 : int.Parse(amountString);
            var currencyCode = _currencyCodeEditText.Text;
            var note         = _noteEditText.Text;

            var tenderTypes = new List <ChargeRequest.TenderType>();

            if (_cardCheckbox.Checked)
            {
                tenderTypes.Add(ChargeRequest.TenderType.Card);
            }
            if (_cashCheckbox.Checked)
            {
                tenderTypes.Add(ChargeRequest.TenderType.Cash);
            }
            if (_otherTenderCheckbox.Checked)
            {
                tenderTypes.Add(ChargeRequest.TenderType.Other);
            }

            var locationId    = _locationIdEditText.Text;
            var timeoutString = _autoReturnTimeoutEditText.Text;
            var timeout       = string.IsNullOrWhiteSpace(timeoutString)
                ? RegisterApi.AutoReturnNoTimeout
                : int.Parse(timeoutString);
            var requestMetadata = _requestMetadataEditText.Text;

            var chargeRequest = new ChargeRequest.Builder(amount, CurrencyCode.ValueOf(currencyCode.ToUpper()))
                                .Note(note)
                                .EnforceBusinessLocation(locationId)
                                .AutoReturn(timeout, TimeUnit.Milliseconds)
                                .RequestMetadata(requestMetadata)
                                .RestrictTendersTo(tenderTypes)
                                .Build();

            try
            {
                var chargeIntent = _registerClient.CreateChargeIntent(chargeRequest);
                StartActivityForResult(chargeIntent, ChargeRequestCode);
            }
            catch (ActivityNotFoundException)
            {
                ShowSnackbar("Square Register was just uninstalled.");
            }
        }