/// <summary> /// Starts the native checkout flow. /// </summary> /// <param name="key"> /// A Base64-encoded Android Pay public key found on the Shopify admin page. /// </param> /// <param name="shopMetadata"> /// Some metadata associated with the current shop, such as name and payment settings. /// </param> /// <param name="success"> /// Callback to be invoked when the checkout flow is successfully completed. /// </param> /// <param name="canceled"> /// Callback to be invoked when the checkout flow is canceled by the user. /// </param> /// <param name="failure"> /// Callback to be called when the checkout flow fails. /// </param> public void Checkout( string key, ShopMetadata shopMetadata, CheckoutSuccessCallback success, CheckoutCancelCallback canceled, CheckoutFailureCallback failure ) { // TODO: Store callbacks and extract items we need from the cart to pass to Android Pay. OnSuccess = success; OnCanceled = canceled; OnFailure = failure; var checkout = CartState.CurrentCheckout; MerchantName = shopMetadata.Name; // TODO: Replace with Shop name var pricingLineItems = GetPricingLineItemsFromCheckout(checkout); var pricingLineItemsString = pricingLineItems.ToJsonString(); var currencyCodeString = checkout.currencyCode().ToString("G"); CountryCodeString = shopMetadata.PaymentSettings.countryCode().ToString("G"); var requiresShipping = checkout.requiresShipping(); #if !SHOPIFY_MONO_UNIT_TEST object[] args = { MerchantName, key, pricingLineItemsString, currencyCodeString, CountryCodeString, requiresShipping }; AndroidPayCheckoutSession.Call("checkoutWithAndroidPay", args); if (AndroidPayEventBridge == null) { AndroidPayEventBridge = GlobalGameObject.AddComponent <AndroidPayEventReceiverBridge>(); AndroidPayEventBridge.Receiver = this; } #endif }
/// <summary> /// Starts the process of making a payment through Apple Pay. /// </summary> /// <remarks> /// Displays a payment interface to the user based on the contents of the Cart /// </remarks> /// <param name="key">Merchant ID for Apple Pay from the Apple Developer Portal</param> /// <param name="shopMetadata">The shop's metadata containing name and payment settings</param> /// <param name="success">Delegate method that will be notified upon a successful payment</param> /// <param name="failure">Delegate method that will be notified upon a failure during the checkout process</param> /// <param name="cancelled">Delegate method that will be notified upon a cancellation during the checkout process</param> public void Checkout(string key, ShopMetadata shopMetadata, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { OnSuccess = success; OnCancelled = cancelled; OnFailure = failure; StoreName = shopMetadata.Name; #if !(SHOPIFY_MONO_UNIT_TEST || SHOPIFY_TEST) var checkout = CartState.CurrentCheckout; var supportedNetworksString = SerializedPaymentNetworksFromCardBrands(shopMetadata.PaymentSettings.acceptedCardBrands()); var summaryItems = GetSummaryItemsFromCheckout(checkout); var summaryString = Json.Serialize(summaryItems); var currencyCodeString = checkout.currencyCode().ToString("G"); var countryCodeString = shopMetadata.PaymentSettings.countryCode().ToString("G"); var requiresShipping = checkout.requiresShipping(); if (ApplePayEventBridge == null) { ApplePayEventBridge = GlobalGameObject.AddComponent <ApplePayEventReceiverBridge>(); ApplePayEventBridge.Receiver = this; } if (_CreateApplePaySession(GlobalGameObject.Name, key, countryCodeString, currencyCodeString, supportedNetworksString, summaryString, null, requiresShipping)) { _PresentApplePayAuthorization(); } else { var error = new ShopifyError(ShopifyError.ErrorType.NativePaymentProcessingError, "Unable to create an Apple Pay payment request. Please check that your merchant ID is valid."); OnFailure(error); } #endif }
public override void Checkout(string checkoutURL, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { using (var webCheckoutSession = new AndroidJavaObject(WebCheckoutSessionClassName, GetNativeMessageReceiverName(), checkoutURL)) { SetupWebCheckoutMessageReceiver(success, cancelled, failure); webCheckoutSession.Call("checkout"); } }
public override void Checkout(string checkoutURL, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { SetupWebCheckoutMessageReceiver(success, cancelled, failure); Application.OpenURL(checkoutURL); }
public override void Checkout(string checkoutURL, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { #if !SHOPIFY_MONO_UNIT_TEST SetupWebCheckoutMessageReceiver(success, cancelled, failure); Application.OpenURL(checkoutURL); #endif }
protected void SetupWebCheckoutMessageReceiver(CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { #if !SHOPIFY_MONO_UNIT_TEST if (_messageReceiver == null) { _messageReceiver = GlobalGameObject.AddComponent <WebCheckoutMessageReceiver>(); } _messageReceiver.Init(Client, Cart.CurrentCheckout, success, cancelled, failure); #endif }
public abstract void Checkout(string checkoutURL, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure);
public override void Checkout(string checkoutURL, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { SetupWebCheckoutMessageReceiver(success, cancelled, failure); _CheckoutWithWebView(GetNativeMessageReceiverName(), checkoutURL); }
/// <summary> /// Launches a platform-specific native pay UI for checking out the Cart's contents. Currently supported native pay options /// include: /// - iOS: Launches Apple Pay. /// </summary> /// <exception cref="System.PlatformNotSupportedException">Thrown when invoking this method on an unsupported platform.</exception> /// <param name="key">Vendor-specific key for identifying the merchant. For iOS devices this is the merchant ID.</param> /// <param name="success">called whenever the checkout process has completed successfully.</param> /// <param name="cancelled">called whenever the user cancels out of the native pay flow.</param> /// <param name="failure">called whenever an error or failure is encountered during native pay.</param> public void CheckoutWithNativePay(string key, CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { if (NativeCheckout == null) { throw new PlatformNotSupportedException("Sorry. We haven't implemented native payments for this platform yet."); } State.CheckoutSave(error => { if (error != null) { failure(error); } else { GetShopMetadata((metadata, metadataError) => { if (metadataError != null) { failure(metadataError); } else { NativeCheckout.Checkout(key, metadata.Value, success, cancelled, failure); } }); } }); }
/// <summary> /// Launches a platform-specific web view screen with the Cart's web checkout link loaded. This can be used to perform /// a cart checkout from within your application instead of being directed to an external web application. Typically this /// can be used as a fallback measure in cases where the user's device doesn't support native pay methods. /// </summary> /// <param name="success">called when the web checkout screen has been dismissed and the checkout was successful.</param> /// <param name="cancelled">called when the web checkout screen was dismissed before completing a checkout.</param> /// <param name="failure">called when an error was encountered after the web checkout screen has been dismissed.</param> public void CheckoutWithWebView(CheckoutSuccessCallback success, CheckoutCancelCallback cancelled, CheckoutFailureCallback failure) { if (WebCheckout == null) { throw new PlatformNotSupportedException("Sorry. We haven't implemented web checkout for this platform yet."); } GetWebCheckoutLink(url => { WebCheckout.Checkout(url, success, cancelled, failure); }, error => { failure(error); }); }