コード例 #1
0
        private void InitPaymentForm()
        {
            Task.Run(async() =>
            {
                var paymentMethods    = await DemoBackend.GetPaymentMethods(amount);
                var cardPaymentMethod = paymentMethods.FirstOrDefault(x => x.Type == "scheme");
                if (cardPaymentMethod == null)
                {
                    RunOnUiThread(() => Snackbar.Make(layout, "Credit card payments not available!", Snackbar.LengthLong).Show());
                    return;
                }

                var cardConfigurationBuilder = new CardConfiguration.Builder(this, Config.PublicKey);
                cardConfigurationBuilder.SetEnvironment(Com.Adyen.Checkout.Core.Api.Environment.Europe);
                var cardConfiguration = cardConfigurationBuilder.Build();

                RunOnUiThread(() =>
                {
                    try
                    {
                        var cardComponent = CardComponent.Provider.Get(this, cardPaymentMethod, cardConfiguration) as CardComponent;

                        var cardView = new CardView(this)
                        {
                            Id = View.GenerateViewId()
                        };
                        var cardLayout = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                        cardLayout.AddRule(LayoutRules.AlignParentTop);
                        cardView.Attach(cardComponent, this);
                        layout.AddView(cardView, cardLayout);
                        textViewLoading.Visibility = ViewStates.Gone;

                        cardComponent.Observe(this, new PaymentComponentObserver
                        {
                            Changed = state =>
                            {
                                var paymentMethod = state.Data.PaymentMethod as CardPaymentMethod;

                                Android.Util.Log.Debug("ObserverImpl", $"Onchanged -- Valid: {state.IsValid}, {paymentMethod.Type}");

                                if (state.IsValid)
                                {
                                    fab.Enabled        = true;
                                    this.paymentMethod = paymentMethod;
                                }
                                else
                                {
                                    fab.Enabled = false;
                                }
                            }
                        });
                    }
                    catch (System.Exception ex)
                    {
                        Android.Util.Log.Error("MainActivity", Throwable.FromException(ex), ex.Message);
                    }
                });
            });
        }
コード例 #2
0
        public static async Task <PaymentsResponse> ExecutePayment(CardPaymentMethod paymentMethod, string returnUrl, decimal amount = 10)
        {
            using (var client = CreateHttpClient())
            {
                var response = await client.PostJsonAsync($"{BaseUri.AbsolutePath}payments", new
                {
                    countryCode     = Config.CountryCode,
                    shopperLocale   = Config.ShopperLocale,
                    merchantAccount = Config.MerchantAccount,
                    reference       = Guid.NewGuid().ToString(),               //We just make this up!
                    amount          = new
                    {
                        currency = Config.Currency,
                        value    = amount * 100                      //I think we need to multiply by 100
                    },
                    returnUrl,
                    paymentMethod = new
                    {
                        type = paymentMethod.Type,
                        encryptedCardNumber   = paymentMethod.EncryptedCardNumber,
                        encryptedExpiryMonth  = paymentMethod.EncryptedExpiryMonth,
                        encryptedExpiryYear   = paymentMethod.EncryptedExpiryYear,
                        encryptedSecurityCode = paymentMethod.EncryptedSecurityCode
                    },
                    //This is for 3D Secure
                    additionalData        = new { executeThreeD = true, allow3DS2 = false },
                    merchantRiskIndicator = new { deliveryAddressIndicator = "digitalGoods", deliveryEmail = "*****@*****.**" },
                    shopperEmail          = "*****@*****.**",
                    holderName            = "Test Testsson",
                    channel = "Android"
                });

                if (response.IsSuccessStatusCode)
                {
                    var responseData = await response.Content.DeserializeJsonAsync <PaymentsResponse>();

                    return(responseData);
                }
                else
                {
                    var errorData = await response.Content.DeserializeJsonAsync <ErrorResponse>();

                    Android.Util.Log.Error("DemoBackend", $"{errorData.Message} ({errorData.ErrorCode})");
                    return(new PaymentsResponse
                    {
                        ResultCode = "Error",
                        RefusalReason = $"{errorData.Message} ({errorData.ErrorType})",
                        RefusalReasonCode = errorData.ErrorCode
                    });
                }
            }
        }
コード例 #3
0
 public void ExampleOfPrintingCard()
 {
     var cardType = CardType.Visa;
     var cardNumber = new CardNumber("1234");
     var cardPayment = new CardPaymentMethod(cardType, cardNumber);
     cardPayment.ProcessPayment(
         cash => 0,    //ignore
         cheque => 0,    //ignore
         card =>
         {
             Console.WriteLine("Paid with : {0} {1}", card.CardType, card.CardNumber);
             return 0;
         }
     );
 }