/// <summary>
        /// Example for performing simple create payment request.
        /// </summary>
        public void CreateSimplePaymentRequest()
        {
            //dedicated terminal on the gateway
            string terminal = "AltaPay Dev Terminal";

            //Instantiation of the payment request class
            //this class is used for forwarding all the data needed for create payment request
            //For simple payment request required properties to be set are gateway terminal, shop order ID
            //and amount along with currency
            PaymentRequestRequest paymentRequest = new PaymentRequestRequest
            {
                Terminal    = terminal,
                ShopOrderId = "payment-req-" + Guid.NewGuid().ToString(),
                Amount      = Amount.Get(120.20, Currency.EUR),
                //set the properties for redirection URLs
                //where user should be redirected after submitting payment on the gateway
                Config = new PaymentRequestConfig
                {
                    CallbackFormUrl         = "http://demoshop.pensio.com/Form",
                    CallbackOkUrl           = "http://demoshop.pensio.com/Ok",
                    CallbackFailUrl         = "http://demoshop.pensio.com/Fail",
                    CallbackRedirectUrl     = "http://demoshop.pensio.com/Redirect",
                    CallbackNotificationUrl = "http://demoshop.pensio.com/Notification",
                    CallbackOpenUrl         = "http://demoshop.pensio.com/Open",
                    CallbackVerifyOrderUrl  = "http://demoshop.pensio.com/VerifyOrder"
                }
            };

            //execute create payment method
            PaymentRequestResult paymentRequestResult = _api.CreatePaymentRequest(paymentRequest);

            //Result property contains information if the request was successful or not
            if (paymentRequestResult.Result == Result.Success)
            {
                //URL to the payment form page to redirect user
                string paymentFormURL = paymentRequestResult.Url;

                //Payment request ID returned from the gateway
                string paymentRequestId = paymentRequestResult.PaymentRequestId;
            }
            else
            {
                //error messages contain information about what went wrong
                string errorMerchantMessage = paymentRequestResult.ResultMerchantMessage;
                string errorMessage         = paymentRequestResult.ResultMessage;
            }
        }
Exemple #2
0
        [Test]         // Not really a unit test, just a Klarna calling example
        public static void Main()
        {
            String orderId = "Example_Klarna_" + new Random().Next();

            CustomerAddress address = new CustomerAddress {
                Address    = "Sæffleberggate 56,1 mf",
                City       = "Varde",
                Country    = "DK",
                Firstname  = "Testperson-dk",
                Lastname   = "Approved",
                Region     = "DK",
                PostalCode = "6800"
            };

            PaymentRequestRequest request = new PaymentRequestRequest {
                ShopOrderId  = orderId,
                Terminal     = "AltaPay Klarna DK",
                Amount       = Amount.Get(5.5, Currency.DKK),
                Type         = AuthType.payment,
                CustomerInfo = new CustomerInfo {
                    Email           = "*****@*****.**",
                    Username        = "******",
                    CustomerPhone   = "20123456",
                    BankName        = "My Bank",
                    BankPhone       = "+45 12-34 5678",
                    BillingAddress  = address,
                    ShippingAddress = address
                }
            };

            request.OrderLines = new List <PaymentOrderLine> {
                new PaymentOrderLine {
                    Description = "description 1",
                    ItemId      = "id 01",
                    Quantity    = 1,
                    UnitPrice   = 1.1,
                    GoodsType   = GoodsType.Item
                },
                new PaymentOrderLine {
                    Description = "description 2",
                    ItemId      = "id 02",
                    Quantity    = 2,
                    UnitPrice   = 2.2,
                    GoodsType   = GoodsType.Item
                }
            };


            PaymentRequestResult result = _api.CreatePaymentRequest(request);

            // Access the url below and use the social security number 0801363945 in the page form to complete the Klarna order
            System.Console.WriteLine(result.Url);
        }
        public void CreateSimplePaymentRequest()
        {
            PaymentRequestRequest paymentRequest = new PaymentRequestRequest()
            {
                Terminal    = GatewayConstants.terminal,
                ShopOrderId = "payment-req-" + Guid.NewGuid().ToString(),
                Amount      = Amount.Get(42.34, Currency.EUR),
            };

            PaymentRequestResult result = _api.CreatePaymentRequest(paymentRequest);

            Assert.AreEqual(null, result.ResultMerchantMessage);
            Assert.AreEqual(Result.Success, result.Result);
            Assert.IsNotEmpty(result.Url);
            Assert.IsNotEmpty(result.DynamicJavascriptUrl);
            Assert.IsNotEmpty(result.PaymentRequestId);

            //System.Diagnostics.Process.Start(result.Url);
        }