Kurejito.Gateways.SagePay.VspDirect.SagePayPaymentGateway.Purchase C# (CSharp) Method

Purchase() public method

Attempts to debit the specified amount from the supplied payment card.
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.
public Purchase ( string merchantReference, Kurejito.Payments.Money amount, PaymentCard card ) : PaymentResponse
merchantReference string
amount Kurejito.Payments.Money
card Kurejito.Payments.PaymentCard
return PaymentResponse
        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);
        }

Usage Example

Esempio n. 1
0
 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);
 }
All Usage Examples Of Kurejito.Gateways.SagePay.VspDirect.SagePayPaymentGateway::Purchase