public void subtotalTest()
        {
            AmountDetails target   = GetAmountDetails();
            string        expected = "75";
            string        actual   = target.subtotal;

            Assert.AreEqual(expected, actual);
        }
        public void taxTest()
        {
            AmountDetails target   = GetAmountDetails();
            string        expected = "15";
            string        actual   = target.tax;

            Assert.AreEqual(expected, actual);
        }
        public void ConvertToJsonTest()
        {
            AmountDetails target   = GetAmountDetails();
            string        expected = "{\"subtotal\":\"75\",\"tax\":\"15\",\"shipping\":\"10\",\"fee\":\"2\"}";
            string        actual   = target.ConvertToJson();

            Assert.AreEqual(expected, actual);
        }
        public void feeTest()
        {
            AmountDetails target   = GetAmountDetails();
            string        expected = "2";
            string        actual   = target.fee;

            Assert.AreEqual(expected, actual);
        }
        public void shippingTest()
        {
            AmountDetails target   = GetAmountDetails();
            string        expected = "10";
            string        actual   = target.shipping;

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        public async Task <Authorize3dResponse> Authorize3d(
            string currency,
            string amount,
            PaymentOption paymentOption,
            string relatedTransactionId,
            List <Item> items                   = null,
            string userTokenId                  = null,
            string clientUniqueId               = null,
            string clientRequestId              = null,
            int?isRebilling                     = null,
            AmountDetails amountDetails         = null,
            DeviceDetails deviceDetails         = null,
            CashierUserDetails userDetails      = null,
            UserAddress shippingAddress         = null,
            UserAddress billingAddress          = null,
            DynamicDescriptor dynamicDescriptor = null,
            MerchantDetails merchantDetails     = null,
            Addendums addendums                 = null,
            UrlDetails urlDetails               = null,
            string customSiteName               = null,
            string productId                    = null,
            string customData                   = null,
            string transactionType              = null,
            bool autoPayment3D                  = default,
            string userId                 = null,
            string rebillingType          = null,
            string authenticationTypeOnly = null,
            SubMerchant subMerchant       = null)
        {
            var request = new Authorize3dRequest(merchantInfo, sessionToken, currency, amount, paymentOption, relatedTransactionId)
            {
                Items                  = items,
                UserTokenId            = userTokenId,
                ClientRequestId        = clientRequestId,
                ClientUniqueId         = clientUniqueId,
                IsRebilling            = isRebilling,
                AmountDetails          = amountDetails,
                DeviceDetails          = deviceDetails,
                UserDetails            = userDetails,
                ShippingAddress        = shippingAddress,
                BillingAddress         = billingAddress,
                DynamicDescriptor      = dynamicDescriptor,
                MerchantDetails        = merchantDetails,
                Addendums              = addendums,
                UrlDetails             = urlDetails,
                CustomSiteName         = customSiteName,
                ProductId              = productId,
                CustomData             = customData,
                TransactionType        = transactionType,
                AutoPayment3D          = autoPayment3D,
                UserId                 = userId,
                RebillingType          = rebillingType,
                AuthenticationTypeOnly = authenticationTypeOnly,
                SubMerchant            = subMerchant
            };

            return(await safechargeRequestExecutor.Authorize3d(request));
        }
        private AmountDetails GetAmountDetails()
        {
            AmountDetails amntDetails = new AmountDetails();

            amntDetails.tax      = "15";
            amntDetails.fee      = "2";
            amntDetails.shipping = "10";
            amntDetails.subtotal = "75";
            return(amntDetails);
        }
Beispiel #8
0
        public void detailsTest()
        {
            Amount        target   = GetAmount();
            AmountDetails expected = GetAmountDetails();
            AmountDetails actual   = target.details;

            Assert.AreEqual(expected.subtotal, actual.subtotal);
            Assert.AreEqual(expected.fee, actual.fee);
            Assert.AreEqual(expected.shipping, actual.shipping);
            Assert.AreEqual(expected.subtotal, actual.subtotal);
        }
        public Payment CreatePayment(string email, PaymentMethod paymntMethod, string orderAmount, string orderDescription, string returnUrl, string cancelUrl)
        {
            Payment pymnt = null;

            AmountDetails amountDetails = new AmountDetails();

            amountDetails.shipping = "2";
            amountDetails.tax      = "1";
            amountDetails.subtotal = orderAmount;

            Amount amount = new Amount();

            amount.currency = "USD";
            int total = Convert.ToInt32(amountDetails.tax) + Convert.ToInt32(amountDetails.shipping) + Convert.ToInt32(orderAmount);

            amount.total   = total.ToString();
            amount.details = amountDetails;

            RedirectUrls redirectUrls = new RedirectUrls();

            redirectUrls.return_url = returnUrl;
            redirectUrls.cancel_url = cancelUrl;

            Transaction transaction = new Transaction();

            transaction.amount      = amount;
            transaction.description = orderDescription;
            List <Transaction> transactions = new List <Transaction>();

            transactions.Add(transaction);

            Payer payer = new Payer();

            payer.payment_method = paymntMethod.ToString();

            Payment pyment = new Payment();

            pyment.intent        = "sale";
            pyment.payer         = payer;
            pyment.transactions  = transactions;
            pyment.redirect_urls = redirectUrls;

            pymnt = pyment.Create(accessToken);
            return(pymnt);
        }
Beispiel #10
0
        public string SamplePaymentsData()
        {
            //Create the Sample Data using Model Classes of Payments API


            var clientReferenceInformation = new ClientReferenceInformation {
                code = "TC50171_3"
            };

            var processingInformation = new ProcessingInformation {
                commerceIndicator = "internet"
            };

            var subMerchant = new SubMerchant
            {
                cardAcceptorID     = "1234567890",
                country            = "US",
                phoneNumber        = "650-432-0000",
                address1           = "900 Metro Center",
                postalCode         = "94404-2775",
                locality           = "Foster Cit",
                name               = "Visa Inc",
                administrativeArea = "CA",
                region             = "PEN",
                email              = "*****@*****.**"
            };

            var aggregatorInformation = new AggregatorInformation
            {
                subMerchant  = subMerchant,
                name         = "V-Internatio",
                aggregatorID = "123456789"
            };

            var billTo = new BillTo
            {
                country            = "US",
                lastName           = "VDP",
                address2           = "Address 2",
                address1           = "201 S. Division St.",
                postalCode         = "48104-2201",
                locality           = "Ann Arbor",
                administrativeArea = "MI",
                firstName          = "RTS",
                phoneNumber        = "999999999",
                district           = "MI",
                buildingNumber     = "123",
                company            = "Visa",
                email = "*****@*****.**"
            };

            var amountDetails = new AmountDetails
            {
                totalAmount = "102.21",
                currency    = "USD"
            };

            var orderInformation = new OrderInformation
            {
                billTo        = billTo,
                amountDetails = amountDetails
            };

            var card = new Card
            {
                expirationYear  = "2031",
                number          = "5555555555554444",
                securityCode    = "123",
                expirationMonth = "12",
                type            = "002"
            };

            var paymentInformation = new PaymentInformation {
                card = card
            };

            var payments = new Payments
            {
                clientReferenceInformation = clientReferenceInformation,
                processingInformation      = processingInformation,
                aggregatorInformation      = aggregatorInformation,
                orderInformation           = orderInformation,
                paymentInformation         = paymentInformation
            };

            return(JsonConvert.SerializeObject(payments, Formatting.Indented));
        }
Beispiel #11
0
        // ##Create
        // Sample showing to create a Payment using
        // CreditCard as a FundingInstrument
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;


            // ###Address
            // Base Address object used as shipping or billing
            // address in a payment.
            Address billingAddress = new Address();

            billingAddress.city         = "Johnstown";
            billingAddress.country_code = "US";
            billingAddress.line1        = "52 N Main ST";
            billingAddress.postal_code  = "43210";
            billingAddress.state        = "OH";

            // ###CreditCard
            // A resource representing a credit card that can be
            // used to fund a payment.
            CreditCard crdtCard = new CreditCard();

            crdtCard.billing_address = billingAddress;
            crdtCard.cvv2            = "874";
            crdtCard.expire_month    = "11";
            crdtCard.expire_year     = "2018";
            crdtCard.first_name      = "Joe";
            crdtCard.last_name       = "Shopper";
            crdtCard.number          = "4417119669820331";
            crdtCard.type            = "visa";

            // ###AmountDetails
            // Let's you specify details of a payment amount.
            AmountDetails amntDetails = new AmountDetails();

            amntDetails.shipping = "1";
            amntDetails.subtotal = "5";
            amntDetails.tax      = "1";

            // ###Amount
            // Let's you specify a payment amount.
            Amount amnt = new Amount();

            amnt.currency = "USD";
            // Total must be equal to sum of shipping, tax and subtotal.
            amnt.total   = "7";
            amnt.details = amntDetails;

            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. Transaction is created with
            // a `Payee` and `Amount` types
            Transaction tran = new Transaction();

            tran.amount      = amnt;
            tran.description = "This is the payment transaction description.";

            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            List <Transaction> transactions = new List <Transaction>();

            transactions.Add(tran);

            // ###FundingInstrument
            // A resource representing a Payeer's funding instrument.
            // Use a Payer ID (A unique identifier of the payer generated
            // and provided by the facilitator. This is required when
            // creating or using a tokenized funding instrument)
            // and the `CreditCardDetails`
            FundingInstrument fundInstrument = new FundingInstrument();

            fundInstrument.credit_card = crdtCard;

            // The Payment creation API requires a list of
            // FundingInstrument; add the created `FundingInstrument`
            // to a List
            List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>();

            fundingInstrumentList.Add(fundInstrument);

            // ###Payer
            // A resource representing a Payer that funds a payment
            // Use the List of `FundingInstrument` and the Payment Method
            // as 'credit_card'
            Payer payr = new Payer();

            payr.funding_instruments = fundingInstrumentList;
            payr.payment_method      = "credit_card";

            // ###Payment
            // A Payment Resource; create one using
            // the above types and intent as `sale`
            Payment pymnt = new Payment();

            pymnt.intent       = "sale";
            pymnt.payer        = payr;
            pymnt.transactions = transactions;

            try
            {
                // ###AccessToken
                // Retrieve the access token from
                // OAuthTokenCredential by passing in
                // ClientID and ClientSecret
                // It is not mandatory to generate Access Token on a per call basis.
                // Typically the access token can be generated once and
                // reused within the expiry window
                string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();

                // ### Api Context
                // Pass in a `ApiContext` object to authenticate
                // the call and to send a unique request id
                // (that ensures idempotency). The SDK generates
                // a request id if you do not pass one explicitly.
                APIContext apiContext = new APIContext(accessToken);
                // Use this variant if you want to pass in a request id
                // that is meaningful in your application, ideally
                // a order id.
                // String requestId = Long.toString(System.nanoTime();
                // APIContext apiContext = new APIContext(accessToken, requestId ));

                // Create a payment by posting to the APIService
                // using a valid AccessToken
                // The return object contains the status;
                Payment createdPayment = pymnt.Create(apiContext);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }
            CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
Beispiel #12
0
        public async Task <OpenOrderResponse> OpenOrder(

            string currency,
            string amount,
            List <Item> items = null,
            OpenOrderPaymentOption paymentOption = null,
            UserPaymentOption userPaymentOption  = null,
            string paymentMethod                = null,
            string userTokenId                  = null,
            string clientUniqueId               = null,
            string clientRequestId              = null,
            string userId                       = null,
            string authenticationTypeOnly       = null,
            AmountDetails amountDetails         = null,
            DeviceDetails deviceDetails         = null,
            CashierUserDetails userDetails      = null,
            UserAddress shippingAddress         = null,
            UserAddress billingAddress          = null,
            DynamicDescriptor dynamicDescriptor = null,
            MerchantDetails merchantDetails     = null,
            Addendums addendums                 = null,
            UrlDetails urlDetails               = null,
            string customSiteName               = null,
            string productId                    = null,
            string customData                   = null,
            string transactionType              = null,
            string isMoto                       = null,
            string isRebilling                  = null,
            string rebillingType                = null,
            SubMerchant subMerchant             = null)
        {
            var request = new OpenOrderRequest(merchantInfo, sessionToken, currency, amount)
            {
                Items                  = items,
                PaymentOption          = paymentOption,
                UserPaymentOption      = userPaymentOption,
                PaymentMethod          = paymentMethod,
                UserTokenId            = userTokenId,
                ClientRequestId        = clientRequestId,
                ClientUniqueId         = clientUniqueId,
                UserId                 = userId,
                AuthenticationTypeOnly = authenticationTypeOnly,
                AmountDetails          = amountDetails,
                DeviceDetails          = deviceDetails,
                UserDetails            = userDetails,
                ShippingAddress        = shippingAddress,
                BillingAddress         = billingAddress,
                DynamicDescriptor      = dynamicDescriptor,
                MerchantDetails        = merchantDetails,
                Addendums              = addendums,
                UrlDetails             = urlDetails,
                CustomSiteName         = customSiteName,
                ProductId              = productId,
                CustomData             = customData,
                TransactionType        = transactionType,
                IsMoto                 = isMoto,
                IsRebilling            = isRebilling,
                RebillingType          = rebillingType,
                SubMerchant            = subMerchant
            };

            return(await safechargeRequestExecutor.OpenOrder(request));
        }
Beispiel #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;
            Payment     pymnt       = null;

            // ## ExecutePayment
            if (Request.Params["PayerID"] != null)
            {
                pymnt = new Payment();
                if (Request.Params["guid"] != null)
                {
                    pymnt.id = (string)Session[Request.Params["guid"]];
                }
                try
                {
                    // ###AccessToken
                    // Retrieve the access token from
                    // OAuthTokenCredential by passing in
                    // ClientID and ClientSecret
                    // It is not mandatory to generate Access Token on a per call basis.
                    // Typically the access token can be generated once and
                    // reused within the expiry window
                    string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();

                    // ### Api Context
                    // Pass in a `ApiContext` object to authenticate
                    // the call and to send a unique request id
                    // (that ensures idempotency). The SDK generates
                    // a request id if you do not pass one explicitly.
                    APIContext apiContext = new APIContext(accessToken);
                    // Use this variant if you want to pass in a request id
                    // that is meaningful in your application, ideally
                    // a order id.
                    // String requestId = Long.toString(System.nanoTime();
                    // APIContext apiContext = new APIContext(accessToken, requestId ));
                    PaymentExecution pymntExecution = new PaymentExecution();
                    pymntExecution.payer_id = Request.Params["PayerID"];

                    Payment executedPayment = pymnt.Execute(apiContext,
                                                            pymntExecution);
                    CurrContext.Items.Add("ResponseJson", JObject.Parse(executedPayment.ConvertToJson()).ToString(Formatting.Indented));
                }
                catch (PayPal.Exception.PayPalException ex)
                {
                    CurrContext.Items.Add("Error", ex.Message);
                }
            }

            // ## Creating Payment
            else
            {
                // ###Payer
                // A resource representing a Payer that funds a payment
                // Payment Method
                // as `paypal`
                Payer payr = new Payer();
                payr.payment_method = "paypal";
                Random rndm = new Random();
                var    guid = Convert.ToString(rndm.Next(100000));

                string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal.aspx?";

                // # Redirect URLS
                RedirectUrls redirUrls = new RedirectUrls();
                redirUrls.cancel_url = baseURI + "guid=" + guid;
                redirUrls.return_url = baseURI + "guid=" + guid;

                // ###AmountDetails
                // Let's you specify details of a payment amount.
                AmountDetails amntDetails = new AmountDetails();
                amntDetails.tax      = "15";
                amntDetails.shipping = "10";
                amntDetails.subtotal = "75";

                // ###Amount
                // Let's you specify a payment amount.
                Amount amnt = new Amount();
                amnt.currency = "USD";
                // Total must be equal to sum of shipping, tax and subtotal.
                amnt.total   = "100";
                amnt.details = amntDetails;

                // ###Transaction
                // A transaction defines the contract of a
                // payment - what is the payment for and who
                // is fulfilling it. Transaction is created with
                // a `Payee` and `Amount` types
                List <Transaction> transactionList = new List <Transaction>();
                Transaction        tran            = new Transaction();
                tran.description = "Transaction description.";
                tran.amount      = amnt;
                // The Payment creation API requires a list of
                // Transaction; add the created `Transaction`
                // to a List
                transactionList.Add(tran);

                // ###Payment
                // A Payment Resource; create one using
                // the above types and intent as 'sale'
                pymnt               = new Payment();
                pymnt.intent        = "sale";
                pymnt.payer         = payr;
                pymnt.transactions  = transactionList;
                pymnt.redirect_urls = redirUrls;

                try
                {
                    // ###AccessToken
                    // Retrieve the access token from
                    // OAuthTokenCredential by passing in
                    // ClientID and ClientSecret
                    // It is not mandatory to generate Access Token on a per call basis.
                    // Typically the access token can be generated once and
                    // reused within the expiry window
                    string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();

                    // ### Api Context
                    // Pass in a `ApiContext` object to authenticate
                    // the call and to send a unique request id
                    // (that ensures idempotency). The SDK generates
                    // a request id if you do not pass one explicitly.
                    APIContext apiContext = new APIContext(accessToken);
                    // Use this variant if you want to pass in a request id
                    // that is meaningful in your application, ideally
                    // a order id.
                    // String requestId = Long.toString(System.nanoTime();
                    // APIContext apiContext = new APIContext(accessToken, requestId ));

                    // Create a payment by posting to the APIService
                    // using a valid AccessToken
                    // The return object contains the status;
                    Payment createdPayment = pymnt.Create(apiContext);

                    CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));

                    var links = createdPayment.links.GetEnumerator();

                    while (links.MoveNext())
                    {
                        Link lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            CurrContext.Items.Add("RedirectURL", lnk.href);
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                }
                catch (PayPal.Exception.PayPalException ex)
                {
                    CurrContext.Items.Add("Error", ex.Message);
                }
            }
            CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
        public void AmountDetailsConstructorTest()
        {
            AmountDetails target = new AmountDetails();

            Assert.IsNotNull(target);
        }