Represents a credit or debit card used for online payments
 public PaymentResponse Authorise(string merchantReference, Money amount, PaymentCard card)
 {
     if (merchantReference == null) throw new ArgumentNullException("merchantReference");
     if (card == null) throw new ArgumentNullException("card");
     ThrowIfFailPaymentChecks(amount, card);
     return ProcessResponse(this.Post(this.BuildDirectPaymentRequestMessage(card, amount, "Authorization")));
 }
        private void Verify_Sagepay_Status_Code(string sagePayStatus, PaymentStatus expectedStatus)
        {
            var http = new Mock<IHttpPostTransport>();
            http
                .Setup(h => h.Post(It.IsAny<Uri>(), It.IsAny<string>()))
                .Returns(this.MakePostResponse(sagePayStatus));

            var gw = new SagePayPaymentGateway(http.Object, VENDOR_NAME, VPS_PROTOCOL, GatewayMode.Simulator);
            var card = new PaymentCard("I M LOADED", "123412341234134", "1212", "123", CardType.Visa);
            var response = gw.Purchase("123456", new Money(123.45m, new Currency("GBP")), card);
            Assert.Equal(expectedStatus, response.Status);
        }
 public void SagePay_Response_Contains_Payment_Id()
 {
     var http = new Mock<IHttpPostTransport>();
     var vpsTxId = "{00001111-2222-3333-4444-556677889900}";
     var sagepay = new SagePayPaymentGateway(http.Object, "rockshop", 2.23m, GatewayMode.Live);
     http
         .Setup(h => h.Post(It.IsAny<Uri>(), It.IsAny<string>()))
         .Returns(this.MakePostResponse("OK", vpsTxId));
     var card = new PaymentCard("I M LOADED", "123412341234134", "1212", "123", CardType.Visa);
     var response = sagepay.Purchase("1234", new Money(123.45m, new Currency("GBP")), card);
     Assert.Equal(vpsTxId, response.PaymentId);
 }
Example #4
0
 /// <summary>Attempts to debit the specified amount from the supplied payment card.</summary>
 /// <param name="merchantReference">An alphanumeric reference supplied by the merchant that uniquely identifies this transaction</param>
 /// <param name="amount">The amount of money to be debited from the payment card</param>
 /// <param name="currency">The ISO4217 currency code of the currency to be used for this transaction.</param>
 /// <param name="card">An instance of <see cref="PaymentCard"/> containing the customer's payment card details.</param>
 /// <returns>A <see cref="PaymentResponse"/> indicating whether the transaction succeeded.</returns>
 public PaymentResponse Purchase(string merchantReference, decimal amount, string currency, PaymentCard card)
 {
     if (amount > 10.0m) {
         return (new PaymentResponse() {
             Status = PaymentStatus.Declined,
             Reason = "Sorry - FakeBank only accepts transactions under a tenner!"
         });
     }
     return (new PaymentResponse() {
         Status = PaymentStatus.OK,
         Reason = "Payment successful"
     });
 }
 /// <summary>
 /// Attempts to debit the specified amount from the supplied payment card.
 /// </summary>
 /// <param name="merchantReference">An alphanumeric reference supplied by the merchant that uniquely identifies this transaction</param>
 /// <param name="amount">The amount of money to be debited from the payment card (includes the ISO4217 currency code).</param>
 /// <param name="card">An instance of <see cref="PaymentCard"/> containing the customer's payment card details.</param>
 /// <returns>
 /// A <see cref="PaymentResponse"/> indicating whether the transaction succeeded.
 /// </returns>
 public PaymentResponse Purchase(string merchantReference, Money amount, PaymentCard card)
 {
     var xml = new XDocument(
         new XDeclaration("1.0", "UTF-8", null),
         new XElement("Request",
                      MakeAuthenticationElement(),
                      MakeTransactionElement(merchantReference, amount, amount.Currency.Iso3LetterCode, card, Method.auth)
             )
         );
     var response = http.Post(new Uri(gatewayUri),
                                 xml.ToString(SaveOptions.DisableFormatting));
     var xmlResponse = XDocument.Parse(response);
     var paymentResponse = this.PopulateResponse(xmlResponse);
     return (paymentResponse);
 }
 /// <summary>Attempts to debit the specified amount from the supplied payment card.</summary>
 public PaymentResponse Purchase(string merchantReference, decimal amount, string currency, PaymentCard card)
 {
     var data = MakePostData();
     data.Add("TxType", "PAYMENT");
     data.Add("VendorTxCode", merchantReference);
     data.Add("Amount", amount.ToString("0.00"));
     data.Add("Currency", currency);
     data.Add("CardHolder", card.CardHolder);
     data.Add("CardNumber", card.CardNumber);
     data.Add("CardType", TranslateCardType(card.CardType));
     data.Add("ExpiryDate", card.ExpiryDate.ToString());
     var postData = FormatPostData(data);
     var uri = postUris[this.mode];
     var httpResponse = http.Post(uri, postData);
     return (new PaymentResponse() { Reason = httpResponse });
 }
 /// <summary>Attempts to debit the specified amount from the supplied payment card.</summary>
 /// <remarks>Because the SagePay gateway requires a shopping basket, this overload will create
 ///  a simple basket containing a single line item whose description is auto-generated from the 
 /// supplied order details.</remarks>
 public PaymentResponse Purchase(string merchantReference, Money amount, PaymentCard card)
 {
     var data = MakePostData();
     data.Add("TxType", "PAYMENT");
     data.Add("VendorTxCode", merchantReference);
     data.Add("Amount", amount.ToString("0.00"));
     data.Add("Currency", amount.Currency.Iso3LetterCode);
     data.Add("CardHolder", card.CardHolder);
     data.Add("CardNumber", card.CardNumber);
     data.Add("CardType", TranslateCardType(card.CardType));
     data.Add("ExpiryDate", card.ExpiryDate.ToString());
     data.Add("Basket", CreateBasketString(merchantReference, amount));
     data.Add("Description", "DUMMY DESCRIPTION");
     var postData = FormatPostData(data);
     var uri = postUris[this.mode];
     var httpResponse = http.Post(uri, postData);
     var response = this.ParseResponse(httpResponse);
     return (response);
 }
        public void PayPal_Error_Code_CorrectlyTranslates_To_Kurejito_Code(double code, string kurejitoErrorCode, string shortMessage, string longMessage, string correctiveAction)
        {
            //https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_testing_SBTestErrorConditions

            var payPalNvpPaymentGateway = new PayPalDirectPaymentGateway(new HttpTransport(), PayPalEnvironment.NegativeTestAccountSandboxEnvironmentForGbr());
            var amount = Convert.ToDecimal(code/100);
            var expectedStatus = Enum.Parse(typeof (PaymentStatus), kurejitoErrorCode);
            var paymentCard = new PaymentCard("BEN TAYLOR", "4716034283508634", new CardDate(10, 2015), "123", CardType.Visa);
            payPalNvpPaymentGateway.Purchase("REF", new Money(amount, new Currency("GBP")), paymentCard).Status.ShouldEqual(expectedStatus);
        }
 private static ValidationResult Validate(PaymentCard paymentCard)
 {
     var validationResult = new PaymentCardValidator().Validate(paymentCard);
     return validationResult;
 }
 /// <summary>Attempts to debit the specified amount from the supplied payment card.</summary>
 /// <param name="merchantReference">An alphanumeric reference supplied by the merchant that uniquely identifies this transaction</param>
 /// <param name="amount">The amount of money to be debited from the payment card</param>
 /// <param name="currency">The ISO4217 currency code of the currency to be used for this transaction.</param>
 /// <param name="card">An instance of <see cref="PaymentCard"/> containing the customer's payment card details.</param>
 /// <returns>A <see cref="PaymentResponse"/> indicating whether the transaction succeeded.</returns>
 public PaymentResponse Purchase(string merchantReference, decimal amount, string currency, PaymentCard card)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///   Attempts to debit the specified amount from the supplied payment card.
 /// </summary>
 /// <param name = "merchantReference">An alphanumeric reference supplied by the merchant that uniquely identifies this transaction</param>
 /// <param name = "amount">The amount of money to be debited from the payment card (includes the ISO4217 currency code).</param>
 /// <param name = "card">An instance of <see cref = "PaymentCard" /> containing the customer's payment card details.</param>
 /// <returns>
 ///   A <see cref = "PaymentResponse" /> indicating whether the transaction succeeded.
 /// </returns>
 public PaymentResponse Purchase(string merchantReference, Money amount, PaymentCard card)
 {
     ThrowIfFailPaymentChecks(amount, card);
     return ProcessResponse(this.Post(this.BuildDirectPaymentRequestMessage(card, amount, "Sale")));
 }
        private void ThrowIfFailPaymentChecks(Money amount, PaymentCard card)
        {
            if(!Accepts(amount.Currency, card.CardType)) {
                throw new ArgumentOutOfRangeException("card", String.Format("Gateway cannot accept CardType of {0} with currency {1} in {2}.", card.CardType, amount.Currency.Iso3LetterCode, this.environment.AccountCountry));
            }

            if (amount <= 0)
                throw new ArgumentException(@"Purchase amount must be greater than zero.", "amount");

            string ppCreditCardType;
            if (!CardTypeToPayPalCardStringMap.TryGetValue(card.CardType, out ppCreditCardType))
                throw new ArgumentException(string.Format("PaymentCard.CardType must be one of the following: {0}", String.Join(" ", CardTypeToPayPalCardStringMap.Keys.Select(e => e.ToString()).ToArray())));
        }
        private string BuildDirectPaymentRequestMessage(PaymentCard card, Money amount, string paymentAction)
        {
            var pairs = new Dictionary<string, string> {
                                                           {"VERSION", this.environment.Version},
                                                           {"SIGNATURE", this.environment.Signature},
                                                           {"USER", this.environment.Username},
                                                           {"PWD", this.environment.Password},
                                                           {"METHOD", "DoDirectPayment"}, //Required
                                                           {"PAYMENTACTION", paymentAction}, //Other option is Authorization. Use when we do Auth and capture.
                                                           {"IPADDRESS", "192.168.1.1"}, //TODO Required for fraud purposes.
                                                           {"AMT", amount.ToString("0.00")},
                                                           {"CREDITCARDTYPE", CardTypeToPayPalCardStringMap[card.CardType]},
                                                           {"ACCT", card.CardNumber},
                                                           {"EXPDATE", card.ExpiryDate.TwoDigitMonth + card.ExpiryDate.Year},
                                                           {"CVV2", card.CV2},
                                                           //TODO billing address data for PayPal.
                                                           {"FIRSTNAME", "Bob"},
                                                           {"LASTNAME", "Le Builder"},
                                                           {"STREET", "1972 Toytown"},
                                                           {"CITY", "London"},
                                                           {"STATE", "London"},
                                                           {"ZIP", "N1 3JS"},
                                                           //TODO check how values for currency relate to PayPal currency codes
                                                           //https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_country_codes
                                                           {"COUNTRYCODE", "GB"}, //TODO
                                                           {"CURRENCYCODE", amount.Currency.Iso3LetterCode}
                                                       };

            var values =
                pairs.Select(pair => String.Format("{0}={1}", pair.Key, HttpUtility.UrlEncode(pair.Value)));
            return (String.Join("&", values.ToArray()));
        }
Example #14
0
 public SagePayUnitTests()
 {
     http = new Mock<IHttpPostTransport>();
     gateway = new SagePayPaymentGateway(http.Object, VENDOR_NAME, VPS_PROTOCOL, GatewayMode.Simulator);
     card = new PaymentCard("I M LOADED", "13412341341234", "1212", "123", CardType.Visa);
 }
        private static XElement MakeCardTxnElement(PaymentCard card, Method method)
        {
            var cardElement = new XElement("Card",
                                           new XElement("pan", card.CardNumber),
                                           new XElement("expirydate", card.ExpiryDate.MM_YY)
                );
            if (card.HasStartDate) cardElement.Add(new XElement("startdate", card.StartDate.MM_YY));
            if (card.HasIssueNumber) cardElement.Add(new XElement("issuenumber", card.IssueNumber));

            var cardTxnElement = new XElement("CardTxn",
                                              cardElement,
                                              new XElement("method", method)
                );
            return (cardTxnElement);
        }
        private XElement MakeTransactionElement(string merchantreference, decimal amount, string currency,
												PaymentCard card, Method method)
        {
            return (new XElement("Transaction",
                                 MakeCardTxnElement(card, method),
                                 MakeTxnDetailsElement(merchantreference, amount, currency)
                ));
        }