예제 #1
0
        public void Initialize(StripeConfig stripeConfig)
        {
            if (_paymentContext != null)
            {
                return;
            }

            if (STPPaymentConfiguration.SharedConfiguration().PublishableKey == null)
            {
                STPPaymentConfiguration.SharedConfiguration().PublishableKey = stripeConfig.ApiKey;
            }

            var stripeRemoteService =
                new StripeRemoteService(stripeConfig, _restHttpClient, _logManager, _jsonSerializer);
            var provider        = new StripeEphemeralKeyProvider(stripeRemoteService, _logManager);
            var customerContext = new CustomerContext(provider, stripeRemoteService);

            _paymentContext = new STPPaymentContext(
                customerContext,
                STPPaymentConfiguration.SharedConfiguration(),
                STPTheme.DefaultTheme)
            {
                HostViewController = _getUiViewControllerFunc(),
                Delegate           = new PaymentDelegate(_messageHub, stripeRemoteService)
            };
        }
예제 #2
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            STPPaymentConfiguration.SharedConfiguration().PublishableKey = "";
            throw new System.NotSupportedException("Please enter your key");

            return(true);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            var config = STPPaymentConfiguration.SharedConfiguration();

            config.ShippingType = STPShippingType.Shipping;
            config.RequiredShippingAddressFields = PassKit.PKAddressField.PostalAddress | PassKit.PKAddressField.Phone;

            paymentContext = new STPPaymentContext(new MyAPIClient(), config, STPTheme.DefaultTheme);

            paymentContext.PaymentCurrency = "USD";
            paymentContext.PaymentAmount   = 1000;

            paymentContext.WeakDelegate       = this;
            paymentContext.HostViewController = this;
        }
        private void Pay()
        {
            if (!paymentTextField.IsValid)
            {
                return;
            }
            UpdateUIWhenPaymentInProgress(true);

            var             config       = STPPaymentConfiguration.SharedConfiguration();
            nuint           centAmount   = (nuint)(10 * 100);
            string          cur          = "sgd";
            STPAPIClient    stripeClient = new STPAPIClient(config);
            STPSourceParams sourceParams = STPSourceParams.CardParamsWithCard(paymentTextField.CardParams);

            stripeClient.CreateSourceWithParams(sourceParams, (STPSource source, NSError error) =>
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine(error.ToString());
                    return;
                }
                if (source.CardDetails.ThreeDSecure == STPSourceCard3DSecureStatus.Required)
                {
                    //TODO: need update currency for stripeAPI.
                    var threeSourceParams = STPSourceParams.ThreeDSecureParamsWithAmount(centAmount, cur, REDIRECT_URL, (source).StripeID);
                    stripeClient.CreateSourceWithParams(threeSourceParams, (STPSource arg0, NSError arg1) =>
                    {
                        if (error != null)
                        {
                            System.Diagnostics.Debug.WriteLine("Payment Failed");
                        }
                        else
                        {
                            STPRedirectContext redirectContext = new STPRedirectContext(arg0, (string sourceId, string clientSecret, NSError arg2) =>
                            {
                                STPAPIClient.SharedClient().StartPollingSourceWithId(sourceId, clientSecret, 10, (STPSource sourcex, NSError errorx) =>
                                {
                                    UpdateUIWhenPaymentInProgress(false);
                                    switch (sourcex.Status)
                                    {
                                    case STPSourceStatus.Chargeable:
                                        //TODO: charge.
                                        Charge(source.StripeID, (int)centAmount);
                                        //ViewModel.Charge((sourcex).StripeID, _order);
                                        break;

                                    case STPSourceStatus.Consumed:
                                        //TODO: continute payment.
                                        Debug.WriteLine("Payment Success");
                                        //Navigator.NavigateTo((int)ScreenKey.PaymentCompleted);
                                        break;

                                    case STPSourceStatus.Canceled:
                                        break;

                                    case STPSourceStatus.Pending:
                                    case STPSourceStatus.Failed:
                                    case STPSourceStatus.Unknown:
                                        //UserDialogs.Instance.AlertEx("Payment Failed");
                                        System.Diagnostics.Debug.WriteLine("Payment Failed");
                                        break;
                                    }
                                });
                            });

                            redirectContext.StartRedirectFlowFromViewController(this);
                        }
                    });
                }
                else
                {
                    if (source != null)
                    {
                        string stripeID = (source).StripeID;
                        //ViewModel.Charge((source).StripeID, _order);
                        Charge(source.StripeID, (int)centAmount);
                    }
                }
            });
        }