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")));
 }
示例#2
0
        public PaymentResponse Purchase(Money money, CreditCard creditCard)
        {
            if (money.Amount > 10.0m) {
                return(new PaymentResponse() {
                    Status = PaymentStatus.Declined,
                    StatusDetail = "Sorry - FakeBank only accepts transactions under a tenner!"
                });
            }

            return(new PaymentResponse() {
                Status = PaymentStatus.OK,
                StatusDetail = "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);
 }
示例#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 (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)
 {
     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>
 /// <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);
 }
示例#6
0
 public bool Equals(Money otherMoney)
 {
     if (otherMoney == null) return false;
     return Amount.Equals(otherMoney.Amount);
 }
 /// <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()));
        }