Ejemplo n.º 1
0
        /// <summary>
        /// PreparedPayment contacts the server with the payment request data, and returns a GET URL to that
        /// payment. This is convenient for creating an order and then sending the URL e.g. in an email.
        /// </summary>
        /// <returns>PaymentLink</returns>
        public Uri PreparePayment(String ipAddress)
        {
            IpAddress = ipAddress;
            CalculateRequestValues();
            var    xmlBuilder = new HostedXmlBuilder();
            string xml        = xmlBuilder.GetXml(this);

            var secretWord = CrOrderBuilder.GetConfig()
                             .GetSecretWord(PaymentType.HOSTED, CrOrderBuilder.GetCountryCode());
            var sentMerchantId = CrOrderBuilder.GetConfig()
                                 .GetMerchantId(PaymentType.HOSTED, CrOrderBuilder.GetCountryCode());
            var payPageUrl = CrOrderBuilder.GetConfig()
                             .GetEndPoint(PaymentType.HOSTED);

            var baseUrl = payPageUrl.Replace("/payment", "");

            var hostedRequest = new HostedAdminRequest(xml, secretWord, sentMerchantId, baseUrl);

            var targetAddress = baseUrl + "/rest/preparepayment";

            var message    = HostedAdminRequest.HostedAdminCall(targetAddress, hostedRequest).Message;
            var messageDoc = new XmlDocument();

            messageDoc.LoadXml(message);
            var paymentId = messageDoc.SelectSingleNode("//id").InnerText;

            return(new Uri(baseUrl + "/preparedpayment/" + paymentId));
        }
        public void TestRecur()
        {
            const string customerRefNo       = "Customer reference number or client order number";
            const string subscriptionId      = "The subscription id";
            const long   amount              = 66600L;
            var          hostedActionRequest = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
                                               .Recur(new Recur(
                                                          customerRefNo: customerRefNo,
                                                          subscriptionId: subscriptionId,
                                                          currency: Currency.SEK,
                                                          amount: amount
                                                          ));

            HostedAdminRequest hostedAdminRequest = hostedActionRequest.PrepareRequest();

            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/recur/currency").InnerText, Is.EqualTo(Currency.SEK.ToString()));
            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/recur/amount").InnerText, Is.EqualTo(amount + ""));
            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/recur/customerrefno").InnerText, Is.EqualTo(customerRefNo));
            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/recur/subscriptionid").InnerText, Is.EqualTo(subscriptionId));

            var hostedAdminResponse = hostedActionRequest.DoRequest <HostedAdminResponse>();

            //Call to non-existing subscription
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/statuscode").InnerText, Is.EqualTo("322"));
        }
        public void TestQueryCustomerRefNoDirectPayment()
        {
            var customerRefNo = CreateCustomerRefNo();
            var payment       = MakePreparedPayment(PrepareRegularPayment(PaymentMethod.NORDEASE, customerRefNo));
            var now           = DateTime.Now;

            var hostedActionRequest = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
                                      .Query(new QueryByCustomerRefNo(
                                                 customerRefNo: customerRefNo
                                                 ));

            HostedAdminRequest hostedAdminRequest = hostedActionRequest.PrepareRequest();

            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/query/customerrefno").InnerText, Is.EqualTo(customerRefNo));

            var hostedAdminResponse = hostedActionRequest.DoRequest <HostedAdminResponse>();

            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/statuscode").InnerText, Is.EqualTo("0"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customerrefno").InnerText, Is.EqualTo(customerRefNo));
        }
        public void TestQueryTransactionIdDirectPayment()
        {
            var customerRefNo = CreateCustomerRefNo();
            var payment       = MakePreparedPayment(PrepareRegularPayment(PaymentMethod.NORDEASE, customerRefNo));
            var now           = DateTime.Now;

            var hostedActionRequest = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
                                      .Query(new QueryByTransactionId(
                                                 transactionId: payment.TransactionId
                                                 ));

            HostedAdminRequest hostedAdminRequest = hostedActionRequest.PrepareRequest();

            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/query/transactionid").InnerText, Is.EqualTo(payment.TransactionId + ""));

            var hostedAdminResponse = hostedActionRequest.DoRequest <HostedAdminResponse>();

            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/statuscode").InnerText, Is.EqualTo("0"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customerrefno").InnerText, Is.EqualTo(customerRefNo));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/merchantid").InnerText, Is.EqualTo("1130"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/status").InnerText, Is.EqualTo("SUCCESS"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/amount").InnerText, Is.EqualTo("25000"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/currency").InnerText, Is.EqualTo("SEK"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/vat").InnerText, Is.EqualTo("5000"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/capturedamount").InnerText, Is.EqualTo("25000"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/authorizedamount").InnerText, Is.EqualTo("25000"));

            var created = DateTime.Parse(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/created").InnerText);

            Assert.That(created.Year, Is.EqualTo(now.Year));
            Assert.That(created.Month, Is.EqualTo(now.Month));
            Assert.That(created.Day, Is.EqualTo(now.Day));

            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/creditstatus").InnerText, Is.EqualTo("CREDNONE"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/creditedamount").InnerText, Is.EqualTo("0"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/merchantresponsecode").InnerText, Is.EqualTo("0"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/paymentmethod").InnerText, Is.EqualTo("DBNORDEASE"));

            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customer/firstname").InnerXml, Is.EqualTo("TestCompagniet"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customer/ssn").InnerXml, Is.EqualTo("2345234"));
        }
        public void TestLowerAmount()
        {
            var customerRefNo = CreateCustomerRefNo();
            var payment       = MakePreparedPayment(PrepareRegularPayment(PaymentMethod.KORTCERT, customerRefNo));

            var hostedActionRequest = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
                                      .LowerAmount(new LowerAmount(
                                                       transactionId: payment.TransactionId,
                                                       amountToLower: 666
                                                       ));

            HostedAdminRequest hostedAdminRequest = hostedActionRequest.PrepareRequest();

            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/loweramount/transactionid").InnerText, Is.EqualTo(payment.TransactionId + ""));
            Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/loweramount/amounttolower").InnerText, Is.EqualTo("666"));

            var hostedAdminResponse = hostedActionRequest.DoRequest <HostedAdminResponse>();

            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/statuscode").InnerText, Is.EqualTo("0"));
            Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customerrefno").InnerText, Is.EqualTo(customerRefNo));
        }