Exemple #1
0
        public static async ValueTask <GooglePayClient> GetGooglePayClientAsync(
            this IJSRuntime jsRuntime,
            GooglePayEnvironment?env           = null,
            GooglePayMerchantInfo?merchantInfo = null,
            Func <string, ValueTask>?processPaymentCallback = null,
            Func <GooglePayShippingAddress, ValueTask <GooglePayDisplayShippingOptions> >?getDisplayShippingOptionsCallback = null,
            Func <GooglePaySelectedShippingOption, ValueTask <GooglePayTransactionInfo> >?calculateTransactionInfoCallback  = null)
        {
            if (_client != null)
            {
                return(_client);
            }

            if (env == null)
            {
                env = GooglePayEnvironment.Test;
            }

            CallBackInteropWrapper?processPaymentCallbackWrapper = null;

            if (processPaymentCallback != null)
            {
                processPaymentCallbackWrapper = CallBackInteropWrapper.Create(async(string transactionToken) =>
                {
                    await processPaymentCallback(transactionToken);
                });
            }
            CallBackInteropWrapper?getDisplayShippingOptionsCallbackWrapper = null;

            if (getDisplayShippingOptionsCallback != null)
            {
                getDisplayShippingOptionsCallbackWrapper = CallBackInteropWrapper.CreateWithResult(
                    (GooglePayShippingAddress? shippingAddress) => getDisplayShippingOptionsCallback(shippingAddress)
                    );
            }
            CallBackInteropWrapper?calculateTransactionInfoCallbackWrapper = null;

            if (calculateTransactionInfoCallback != null)
            {
                calculateTransactionInfoCallbackWrapper = CallBackInteropWrapper.CreateWithResult(
                    (GooglePaySelectedShippingOption? selectedShippingOption) => calculateTransactionInfoCallback(selectedShippingOption));
            }
            var jsObjRef = await jsRuntime.InvokeAsync <JsRuntimeObjectRef>(
                "blazorGooglePay.getGooglePaymentsClient",
                env,
                merchantInfo,
                processPaymentCallbackWrapper,
                getDisplayShippingOptionsCallbackWrapper,
                calculateTransactionInfoCallbackWrapper);

            _client = new GooglePayClient(jsRuntime, jsObjRef);
            return(_client);
        }
Exemple #2
0
        private async ValueTask ConfigCallbacks()
        {
            await JsRuntime.AddEventListener(JsObjectRef, "", "onended",
                                             CallBackInteropWrapper.Create(OnEndedCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onisolationchange",
                                             CallBackInteropWrapper.Create(OnIsolationChangeCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onmute",
                                             CallBackInteropWrapper.Create(OnMuteCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onunmute",
                                             CallBackInteropWrapper.Create(OnUnmuteCallback, false)).ConfigureAwait(false);
        }
Exemple #3
0
        public async ValueTask <GooglePayButton> CreateButtonAsync(GoogleButtonType type,
                                                                   GooglePayButtonColor?color = null)
        {
            var button   = new GooglePayButton(_jsRuntime, type, color);
            var callback = CallBackInteropWrapper.Create(async() =>
            {
                var isHandled = await OnButtonClicked(button);
                if (!isHandled)
                {
                    await button.OnClicked();
                }
            },
                                                         serializationSpec: false);

            button.JsObjectRef = await _jsRuntime.InvokeAsync <JsRuntimeObjectRef>(
                "blazorGooglePay.createButton",
                _jsObjectRef,
                callback,
                type,
                color);

            return(button);
        }
Exemple #4
0
 /// <summary>
 /// This event is fired when the browser's resource timing buffer is full.
 /// </summary>
 /// <param name="toDo"></param>
 /// <returns></returns>
 public async Task <IAsyncDisposable> OnResourceTimingBufferFull(Func <Task> toDo)
 {
     return(await jsRuntime.AddEventListener(windowRef, "performance", "resourcetimingbufferfull", CallBackInteropWrapper.Create(toDo)));
 }
 /// <summary>
 /// fired when the screen changes orientation.
 /// </summary>
 /// <param name="toDo"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnChange(Func <ValueTask> toDo)
 {
     return(await jsRuntime.AddEventListener(screenRef, "orientation", "change",
                                             CallBackInteropWrapper.Create(toDo)).ConfigureAwait(false));
 }
Exemple #6
0
 /// <summary>
 /// fired when the screen changes orientation.
 /// </summary>
 /// <param name="toDo"></param>
 /// <returns></returns>
 public async Task <IAsyncDisposable> OnChange(Func <Task> toDo)
 {
     return(await jsRuntime.AddEventListener(windowRef, "screen.orientation", "change", CallBackInteropWrapper.Create(toDo)));
 }