示例#1
0
        public static void CaptureImplicitTotal(PaySession sess)
        {
            var amount = new Financial.Amount("usd", 17.25M);
            var charge = sess.Charge(null, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT,
              amount, false, "test payment");

            Assert.AreEqual(new Financial.Amount("usd", .0M), charge.AmountCaptured);

            charge.Capture(null);

            Assert.AreEqual(amount, charge.AmountCaptured);
        }
示例#2
0
        public static void CaptureExplicitTotal(PaySession sess)
        {
            var amount = new Financial.Amount("usd", 17.25M);

            var charge = sess.Charge(null, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, amount, false, "test payment");

            Assert.IsFalse(charge.IsCaptured);

            charge.Capture(null, amount);

            Assert.IsTrue(charge.IsCaptured);
        }
示例#3
0
        public static void CaptureImplicitTotal(PaySession sess)
        {
            var amount = new Financial.Amount("usd", 17.25M);
            var charge = sess.Charge(null, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT,
                                     amount, false, "test payment");

            Assert.AreEqual(new Financial.Amount("usd", .0M), charge.AmountCaptured);

            charge.Capture(null);

            Assert.AreEqual(amount, charge.AmountCaptured);
        }
示例#4
0
        public static void RefundFullImplicit(PaySession sess)
        {
            var amountToRefund = new Financial.Amount("usd", 17.25M);

            var charge = sess.Charge(null, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, Account.EmptyInstance, amountToRefund, true, "test payment");

            Assert.AreEqual(new Financial.Amount("usd", .0M), charge.AmountRefunded);

            FakePaySystemHost.Instance.SaveTransaction(charge);

            var refund = charge.Refund(null);

            Assert.AreEqual(amountToRefund, charge.AmountRefunded);
            Assert.AreEqual(charge.ID, refund.ParentTransactionID);
        }
示例#5
0
 /// <summary>
 /// Converts financial amount to string per portal
 /// </summary>
 public abstract string AmountToString(Financial.Amount amount,
                                       MoneyFormat format = MoneyFormat.WithCurrencySymbol,
                                       ISession session   = null);
示例#6
0
 public static void Write(WritingStreamer streamer, ulong name, Financial.Amount value)
 {
     streamer.Write(name);
     streamer.Write((byte)DataType.Amount);
     streamer.Write(value);
 }
示例#7
0
 public abstract void Write(Financial.Amount value);
示例#8
0
        public static void RefundFullImplicit(PaySession sess)
        {
            var amountToRefund = new Financial.Amount("usd", 17.25M);

            var charge = sess.Charge(null, FakePaySystemHost.CARD_ACCOUNT_STRIPE_CORRECT, Account.EmptyInstance, amountToRefund, true, "test payment");

            Assert.AreEqual(new Financial.Amount("usd", .0M), charge.AmountRefunded);

            FakePaySystemHost.Instance.SaveTransaction(charge);

            var refund = charge.Refund(null);

            Assert.AreEqual(amountToRefund, charge.AmountRefunded);
            Assert.AreEqual(charge.ID, refund.ParentTransactionID);
        }
示例#9
0
文件: SlimWriter.cs 项目: filmor/nfx
 public override void Write(Financial.Amount value)
 {
     this.Write(value.CurrencyISO);
     this.Write(value.Value);
 }
示例#10
0
        private ShippingRate doEstimateShippingCost(ShippoSession session, IShippingContext context, Shipment shipment, Guid logID)
        {
            var cred  = (ShippoCredentials)session.User.Credentials;
            var sbody = getShipmentBody(shipment);

            // get shipping request
            var request = new WebClient.RequestParams(this)
            {
                Method      = HTTPRequestMethod.POST,
                ContentType = ContentType.JSON,
                Headers     = new Dictionary <string, string>
                {
                    { HDR_AUTHORIZATION, HDR_AUTHORIZATION_TOKEN.Args(cred.PrivateToken) }
                },
                Body = sbody.ToJSON(JSONWritingOptions.Compact)
            };

            var response = WebClient.GetJson(new Uri(URI_API_BASE + URI_SHIPMENTS), request);

            Log(MessageType.Info, "doEstimateShippingCost()", response.ToJSON(), relatedMessageID: logID);

            checkResponse(response);

            var rates = response["rates_list"] as JSONDataArray;

            if (rates == null)
            {
                return(null);
            }

            var bestApprRate = new ShippingRate
            {
                CarrierID = shipment.Carrier.Name,
                ServiceID = shipment.Service.Name,
                PackageID = shipment.Package != null ? shipment.Package.Name : null
            };
            var bestAltRate = new ShippingRate
            {
                CarrierID     = shipment.Carrier.Name,
                ServiceID     = shipment.Service.Name,
                PackageID     = shipment.Package != null ? shipment.Package.Name : null,
                IsAlternative = true
            };

            // try to find rate with requested carrier/service/package (i.e. "appropriate") with the best price
            // if no appropriate rate found, return alternative rate (also with the best price)
            foreach (JSONDataMap rate in rates)
            {
                var carrierID = rate["carrier_account"].AsString();
                var serviceID = rate["servicelevel_token"].AsString();
                var cost      = new Financial.Amount(rate["currency_local"].AsString(), rate["amount_local"].AsDecimal());

                if (shipment.Carrier.Name.EqualsIgnoreCase(carrierID) &&
                    shipment.Service.Name.EqualsIgnoreCase(serviceID))
                {
                    if (bestApprRate.Cost == null ||
                        (bestApprRate.Cost.Value.CurrencyISO.EqualsIgnoreCase(cost.CurrencyISO) && // todo: multiple currencies
                         bestApprRate.Cost.Value.Value > cost.Value))
                    {
                        bestApprRate.Cost = cost;
                    }
                }

                if (bestAltRate.Cost == null ||
                    (bestAltRate.Cost.Value.CurrencyISO.EqualsIgnoreCase(cost.CurrencyISO) && // todo: multiple currencies
                     bestAltRate.Cost.Value.Value > cost.Value))
                {
                    bestAltRate.Cost = cost;
                }
            }

            return((bestApprRate.Cost != null) ? bestApprRate : bestAltRate);
        }
示例#11
0
文件: MockSystem.cs 项目: ame89/nfx
        public override Transaction Transfer(PaySession session, ITransactionContext context, Account from, Account to, Financial.Amount amount, string description = null, object extraData = null)
        {
            var actualAccountData = PaySystemHost.AccountToActualData(context, to);

            if (actualAccountData == null)
            {
                StatTransferError();
                throw new PaymentMockException(StringConsts.PAYMENT_UNKNOWN_ACCOUNT_ERROR.Args(from) + this.GetType().Name + ".Transfer");
            }

            AccountData accountData = null;

            accountData = m_Accounts.DebitBankCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, Account.EmptyInstance, to, this.Name, taId, amount, created, description);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, Account.EmptyInstance, to, this.Name, taId, amount, created, description);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrectWithAddr.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                             c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                             c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                             c.CardVC == actualAccountData.CardVC &&
                                                                             c.BillingAddress1 != actualAccountData.BillingAddress1 &&
                                                                             c.BillingAddress2 != actualAccountData.BillingAddress2 &&
                                                                             c.BillingCountry != actualAccountData.BillingCountry &&
                                                                             c.BillingCity != actualAccountData.BillingCity &&
                                                                             c.BillingPostalCode != actualAccountData.BillingPostalCode &&
                                                                             c.BillingRegion != actualAccountData.BillingRegion &&
                                                                             c.BillingEmail != actualAccountData.BillingEmail &&
                                                                             c.BillingPhone != actualAccountData.BillingPhone);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, Account.EmptyInstance, to, this.Name, taId, amount, created, description);

                StatTransfer(amount);

                return(ta);
            }

            StatTransferError();
            throw new PaymentException(StringConsts.PAYMENT_INVALID_CARD_NUMBER_ERROR + this.GetType().Name + ".Transfer");
        }
示例#12
0
文件: MockSystem.cs 项目: ame89/nfx
        public override Transaction Charge(PaySession session, ITransactionContext context, Account from, Account to, Financial.Amount amount, bool capture = true, string description = null, object extraData = null)
        {
            var fromActualData = PaySystemHost.AccountToActualData(context, from);

            if (fromActualData == null)
            {
                StatChargeError();
                throw new PaymentMockException(StringConsts.PAYMENT_UNKNOWN_ACCOUNT_ERROR.Args(from) + this.GetType().Name + ".Charge");
            }

            if (m_Accounts.CreditCardDeclined.Any(c => c.AccountNumber == fromActualData.AccountNumber))
            {
                StatChargeError();
                throw new PaymentMockException(this.GetType().Name + ".Charge: card '{0}' declined".Args(fromActualData));
            }

            if (m_Accounts.CreditCardLuhnError.Any(c => c.AccountNumber == fromActualData.AccountNumber))
            {
                StatChargeError();
                throw new PaymentMockException(this.GetType().Name + ".Charge: card number '{0}' is incorrect".Args(fromActualData));
            }


            AccountData foundAccount = null;

            foundAccount = m_Accounts.CreditCardsCorrect.FirstOrDefault(c => c.AccountNumber == fromActualData.AccountNumber);

            if (foundAccount != null)
            {
                if (foundAccount.CardExpirationYear != fromActualData.CardExpirationYear)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardExpirationMonth != fromActualData.CardExpirationMonth)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardVC != fromActualData.CardVC)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_CVC_ERROR + this.GetType().Name + ".Charge");
                }

                var created = DateTime.UtcNow;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

                var ta = new Transaction(taId, TransactionType.Charge, from, to, this.Name, taId, amount, created, description);

                StatCharge(amount);

                return(ta);
            }

            foundAccount = m_Accounts.CreditCardCorrectWithAddr.FirstOrDefault(c => c.AccountNumber == fromActualData.AccountNumber);

            if (foundAccount != null)
            {
                if (foundAccount.CardExpirationYear != fromActualData.CardExpirationYear)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardExpirationMonth != fromActualData.CardExpirationMonth)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardVC != fromActualData.CardVC)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_CVC_ERROR.Args(fromActualData.CardVC) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.BillingAddress1 != fromActualData.BillingAddress1 ||
                    foundAccount.BillingAddress2 != fromActualData.BillingAddress2 ||
                    foundAccount.BillingCountry != fromActualData.BillingCountry ||
                    foundAccount.BillingCity != fromActualData.BillingCity ||
                    foundAccount.BillingPostalCode != fromActualData.BillingPostalCode ||
                    foundAccount.BillingRegion != fromActualData.BillingRegion ||
                    foundAccount.BillingEmail != fromActualData.BillingEmail ||
                    foundAccount.BillingPhone != fromActualData.BillingPhone)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_ADDR_ERROR + this.GetType().Name + ".Charge");
                }

                var created = DateTime.UtcNow;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

                var ta = new Transaction(taId, TransactionType.Charge, from, to, this.Name, taId, amount, created, description);

                StatCharge(amount);

                return(ta);
            }

            throw new PaymentException(StringConsts.PAYMENT_INVALID_CARD_NUMBER_ERROR + this.GetType().Name + ".Charge");
        }
示例#13
0
文件: MockSystem.cs 项目: ame89/nfx
 public override PaymentException VerifyPotentialTransaction(PaySession session, ITransactionContext context, bool transfer, IActualAccountData from, IActualAccountData to, Financial.Amount amount)
 {
     throw new NotImplementedException();
 }