public async Task <ISwishPaymentResponse> CreateSwishPayment()
        {
            var totalAmount = this.cartService.CalculateTotal();
            var vatAmount   = new Amount(0);

            try
            {
                var swishRequest = new SwishPaymentRequest(new List <IPrice>(),
                                                           "Test Purchase",
                                                           this.payeeInfoOptions.PayeeReference, "useragent", new Language("sv-SE"), new Urls(this.urls.HostUrls.ToList(), this.urls.CompleteUrl, this.urls.TermsOfServiceUrl)
                {
                    CancelUrl = this.urls.CancelUrl, PaymentUrl = this.urls.PaymentUrl, CallbackUrl = this.urls.CallbackUrl, LogoUrl = this.urls.LogoUrl
                },
                                                           new PayeeInfo(this.payeeInfoOptions.PayeeId, this.payeeInfoOptions.PayeeReference),
                                                           new PrefillInfo(new Msisdn("+46739000001")));
                swishRequest.Payment.Prices.Add(new Price(new Amount(totalAmount), PriceType.Swish, vatAmount));

                var swishPayment = await this.swedbankPayClient.Payments.SwishPayments.Create(swishRequest);

                this.cartService.PaymentLink      = swishPayment.Payment.Id.OriginalString;
                this.cartService.Instrument       = PaymentInstrument.Swish;
                this.cartService.PaymentOrderLink = null;
                this.cartService.Update();

                return(swishPayment);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                return(null);
            }
        }
        public void ValidateExceptionFromApi()
        {
            var httpClient = new HttpClient {
                BaseAddress = new Uri("https://api.externalintegration.payex.com")
            };

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "xxxxx");
            var swedbankPayClient = new SwedbankPayClient(httpClient);
            var payeeRef          = DateTime.Now.Ticks.ToString();
            var amount            = new Amount(1600);
            var vatAmount         = new Amount(0);
            var phoneNumber       = "+46739000001";
            var swishRequest      = new SwishPaymentRequest(
                new List <IPrice>(),
                "Test Purchase", payeeRef, "GetUserAgent()", new Language("sv-SE"),
                new Urls(
                    new List <Uri>(), new Uri("http://api.externalintegration.payex.com"),
                    new Uri("http://api.externalintegration.payex.com")),
                new PayeeInfo(string.Empty, payeeRef),
                new PrefillInfo(new Msisdn(phoneNumber)));

            swishRequest.Payment.Prices.Add(new Price(amount, PriceType.Swish, vatAmount));
            swishRequest.Payment.Urls.HostUrls.Add(new Uri("http://api.externalintegration.payex.com"));
            var error = Assert.ThrowsAsync <HttpResponseException>(() => swedbankPayClient.Payments.SwishPayments.Create(swishRequest));

            Assert.AreEqual(1, error.Data.Keys.Count);
        }
示例#3
0
        public SwishPaymentRequest BuildSwishPaymentRequest()
        {
            var req = new SwishPaymentRequest(this.prices, this.description, this.payerReference, this.userAgent, this.language, this.urls, this.payeeInfo, this.prefillInfo);

            req.Payment.Metadata = this.metadata;

            return(req);
        }
示例#4
0
 public SwishPaymentRequestDto(SwishPaymentRequest paymentRequest)
 {
     Payment = new SwishPaymentRequestDetailsDto(paymentRequest.Payment);
 }