Exemple #1
0
        public TrustlyPaymentRequest BuildTrustlyRequest()
        {
            var req = new TrustlyPaymentRequest(this.currency, this.prices, this.description, this.payerReference, this.userAgent, this.language, this.urls, this.payeeInfo);

            req.Payment.PrefillInfo = trustlyPrefillInfo;
            return(req);
        }
        public async Task <ITrustlyPaymentResponse> CreateTrustlyPayment()
        {
            var totalAmount = this.cartService.CalculateTotal();
            var vatAmount   = new Amount(0);

            try
            {
                var trustlyPaymentRequest = new TrustlyPaymentRequest(
                    new Currency("SEK"),
                    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));

                trustlyPaymentRequest.Payment.Prices.Add(new Price(new Amount(totalAmount),
                                                                   PriceType.Trustly,
                                                                   vatAmount));
                foreach (var url in urls.HostUrls)
                {
                    trustlyPaymentRequest.Payment.Urls.HostUrls.Add(url);
                }

                var trustlyPayment = await this.swedbankPayClient.Payments.TrustlyPayments.Create(trustlyPaymentRequest);

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

                return(trustlyPayment);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                return(null);
            }
        }
 public TrustlyPaymentRequestDto(TrustlyPaymentRequest paymentRequest)
 {
     Payment = new TrustlyPaymentDetailsDto(paymentRequest.Payment);
 }