예제 #1
0
        /// <summary>
        /// Reqister payment at Netaxept. This method will return the transaction id
        /// </summary>
        /// <param name="paymentRequest"></param>
        /// <returns></returns>
        public string Register(PaymentRequest paymentRequest)
        {
            if (paymentRequest == null)
            {
                throw new ArgumentNullException(nameof(paymentRequest));
            }

            paymentRequest.Validate();

            var registerRequest = new RegisterRequest
            {
                ServiceType = "B",
                Terminal    = new Terminal
                {
                    OrderDescription = paymentRequest.OrderDescription,
                    RedirectUrl      = paymentRequest.SuccessUrl,
                    Language         = paymentRequest.Language,
                    Vat = paymentRequest.TaxTotal
                },
                Order = new Order
                {
                    Amount        = paymentRequest.Amount,
                    CurrencyCode  = paymentRequest.CurrencyCode,
                    OrderNumber   = paymentRequest.OrderNumber,
                    Force3DSecure = "true"
                },
                Environment = new Environment
                {
                    WebServicePlatform = "WCF"
                },
                Customer = new Customer
                {
                    CustomerNumber = paymentRequest.CustomerNumber,
                    FirstName      = paymentRequest.CustomerFirstname,
                    LastName       = paymentRequest.CustomerLastname,
                    Email          = paymentRequest.CustomerEmail,
                    Address1       = paymentRequest.CustomerAddress1,
                    Address2       = paymentRequest.CustomerAddress2,
                    Postcode       = paymentRequest.CustomerPostcode,
                    Town           = paymentRequest.CustomerTown,
                    Country        = paymentRequest.CustomerCountry,
                    PhoneNumber    = paymentRequest.CustomerPhoneNumber
                },
            };

            if (paymentRequest.EnableEasyPayments)
            {
                registerRequest.Recurring = new Recurring
                {
                    PanHash = paymentRequest.PanHash,
                    Use3DS  = "true",
                    Type    = "S"
                };
            }

            var response = _client.Register(_connection.MerchantId, _connection.Token, registerRequest);

            return(response.TransactionId);
        }
        /// <summary>
        /// Validates that the currency matches the provider. Makes placeholder request.
        /// </summary>
        public override Payment RequestPayment(PaymentRequest paymentRequest)
        {
            Guard.Against.UnsupportedCurrencyInNetaxept(paymentRequest.Payment.PurchaseOrder.BillingCurrency);
            Guard.Against.Null(paymentRequest.Payment.PurchaseOrder.BillingAddress, "PurchaseOrder.BillingAddress must be supplied for Netaxept payments. Please make sure that you update the property prior to initiating payment either by using the API TransactionLibrary.EditBillingInformation() or setting the property directly.");

            if (paymentRequest.Payment == null)
            {
                paymentRequest.Payment = CreatePayment(paymentRequest);
            }

            Payment payment = paymentRequest.Payment;

            var billingAddress = payment.PurchaseOrder.GetBillingAddress();

            string orderCurrency = paymentRequest.Payment.PurchaseOrder.BillingCurrency.ISOCode;
            string referenceId   = payment.ReferenceId;
            int    orderAmount   = Convert.ToInt32(paymentRequest.Amount.Value.ToCents());
            int    orderTax      = Convert.ToInt32(paymentRequest.PurchaseOrder.VAT.Value.ToCents());

            string customerFirstName  = billingAddress.FirstName;
            string customerLastName   = billingAddress.LastName;
            string customerEmail      = billingAddress.EmailAddress;
            string customerCompany    = billingAddress.CompanyName;
            string customerStreet1    = billingAddress.Line1;
            string customerStreet2    = billingAddress.Line2;
            string customerPostalCode = billingAddress.PostalCode;
            string customerCity       = billingAddress.City;
            string customerCountry    = billingAddress.Country.Name;
            string customerPhone      = string.Format("{0}, {1}", billingAddress.PhoneNumber,
                                                      billingAddress.MobilePhoneNumber);

            // Configuration data
            string merchantId              = paymentRequest.PaymentMethod.DynamicProperty <string>().MerchantId;
            string password                = paymentRequest.PaymentMethod.DynamicProperty <string>().Password;
            string callbackUrl             = paymentRequest.PaymentMethod.DynamicProperty <string>().CallbackUrl;
            string availablePaymentOptions = paymentRequest.PaymentMethod.DynamicProperty <string>().AvailablePaymentOptions;
            bool   singlePageView          = paymentRequest.PaymentMethod.DynamicProperty <bool>().SinglePageView;
            bool   force3DSecure           = paymentRequest.PaymentMethod.DynamicProperty <bool>().Force3DSecure;

            // Placeholder request
            NetaxeptClient   client           = GetClient(paymentRequest.PaymentMethod);
            RegisterResponse registerResponse = client.Register(merchantId, password, new RegisterRequest
            {
                Terminal = new Terminal
                {
                    // Where to send the customer when the transaction has been registred at nets
                    RedirectUrl       = _callbackUrl.GetCallbackUrl(callbackUrl, paymentRequest.Payment),
                    Language          = GetLanguage(),
                    PaymentMethodList = availablePaymentOptions,
                    SinglePage        = singlePageView.ToString(),
                    Vat = orderTax.ToString()
                },
                Order = new Order
                {
                    Amount        = orderAmount.ToString(),
                    CurrencyCode  = orderCurrency,
                    OrderNumber   = referenceId,
                    Force3DSecure = force3DSecure.ToString()
                },
                Customer = new Netaxept.NetaxeptBackendService.Customer
                {
                    FirstName   = customerFirstName,
                    LastName    = customerLastName,
                    Email       = customerEmail,
                    CompanyName = customerCompany,
                    Address1    = customerStreet1,
                    Address2    = customerStreet2,
                    Postcode    = customerPostalCode,
                    Town        = customerCity,
                    Country     = customerCountry,
                    PhoneNumber = customerPhone
                },
                Environment = new Netaxept.NetaxeptBackendService.Environment
                {
                    WebServicePlatform = "WCF"
                }
            });

            RedirectCustomerToRemotePaymentPage(registerResponse.TransactionId, paymentRequest.PaymentMethod);

            return(payment);
        }