示例#1
0
        public async Task <DropUIResult> ShowDropUI(double totalPrice, string merchantId, int requestCode = 1234)
        {
            if (isReady)
            {
                CurrentInstance = this;
                _requestCode    = requestCode;
                dropUiPayTcs    = new TaskCompletionSource <DropUIResult>();
                GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest();

                googlePaymentRequest.InvokeTransactionInfo(TransactionInfo.NewBuilder()
                                                           .SetTotalPrice($"{totalPrice}")
                                                           .SetTotalPriceStatus(WalletConstants.TotalPriceStatusFinal)
                                                           .SetCurrencyCode("USD")
                                                           .Build());

                DropInRequest dropInRequest = new DropInRequest().ClientToken(_clientToken)
                                              .InvokeGooglePaymentRequest(googlePaymentRequest);

                Xamarin.Essentials.Platform.CurrentActivity.StartActivityForResult(dropInRequest.GetIntent(Xamarin.Essentials.Platform.CurrentActivity), requestCode);
            }
            else
            {
                OnDropUIError?.Invoke(this, "Platform is not ready to accept payments");
                dropUiPayTcs.TrySetException(new System.Exception("Platform is not ready to accept payments"));
            }

            return(await dropUiPayTcs.Task);
        }
        /// <inheritdoc />
        /// <summary>
        /// Mark an invoice paid with Google Mark an invoice paid with Google. Verifies signature from Google and treats the developerPayload field inside the json payload as the id of the invoice to pay. Returns the transaction ID if successful. &lt;br&gt;&lt;br&gt;&lt;b&gt;Permissions Needed:&lt;/b&gt; ANY
        /// </summary>
        /// <param name="request">The request for paying an invoice through a Google in-app payment</param>
        public void HandleGooglePayment(GooglePaymentRequest request)
        {
            mWebCallEvent.WebPath = "/payment/provider/google/payments";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(request); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mHandleGooglePaymentStartTime = DateTime.Now;
            mWebCallEvent.Context         = mHandleGooglePaymentResponseContext;
            mWebCallEvent.RequestType     = KnetikRequestType.POST;

            KnetikLogger.LogRequest(mHandleGooglePaymentStartTime, "HandleGooglePayment", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }
示例#3
0
        public async Task <string> TokenizePlatform(double totalPrice, string merchantId)
        {
            payTcs = new TaskCompletionSource <string>();
            if (isReady)
            {
                GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest();

                googlePaymentRequest.InvokeTransactionInfo(TransactionInfo.NewBuilder()
                                                           .SetTotalPrice($"{totalPrice}")
                                                           .SetTotalPriceStatus(WalletConstants.TotalPriceStatusFinal)
                                                           .SetCurrencyCode("USD")
                                                           .Build());

                mBraintreeFragment.AddListener(this);
                GooglePayment.RequestPayment(mBraintreeFragment, googlePaymentRequest);
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new System.Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }