public void Setup() { _returnRequest = new ReturnRequest () { Amount = 100, OrderNumber = "Test1234" }; _executer = new Mock<IWebCommandExecuter>(); }
public void ItShouldThrowArgumentExceptionForInvalidReturn() { // Arrange Gateway beanstream = new Gateway () { MerchantId = 300200578, PaymentsApiKey = "4BaD82D9197b4cc4b70a221911eE9f70", ApiVersion = "1" }; beanstream.WebCommandExecuter = _executer.Object; _returnRequest = null; // Act var ex = (ArgumentNullException)Assert.Throws(typeof(ArgumentNullException), () =>beanstream.Payments.Return(TrnId,_returnRequest)); // Assert Assert.That(ex.ParamName, Is.EqualTo("returnRequest")); }
/// <summary> /// Return a previous payment made through Beanstream /// </summary> /// <returns>The payment result</returns> /// <param name="paymentId">Payment identifier.</param> /// <param name="returnRequest">Return request.</param> public PaymentResponse Return(string paymentId, ReturnRequest returnRequest) { Gateway.ThrowIfNullArgument (returnRequest, "returnRequest"); Gateway.ThrowIfNullArgument (paymentId, "paymentId"); string url = BeanstreamUrls.ReturnsUrl .Replace("{v}", String.IsNullOrEmpty(_configuration.Version) ? "v1" : "v"+_configuration.Version) .Replace("{p}", String.IsNullOrEmpty(_configuration.Platform) ? "www" : _configuration.Platform) .Replace("{id}", String.IsNullOrEmpty(paymentId) ? "" : paymentId); HttpsWebRequest req = new HttpsWebRequest () { MerchantId = _configuration.MerchantId, Passcode = _configuration.PaymentsApiPasscode, WebCommandExecutor = _webCommandExecuter }; returnRequest.MerchantId = _configuration.MerchantId.ToString(); string response = req.ProcessTransaction (HttpMethod.Post, url, returnRequest); Console.WriteLine (response); return JsonConvert.DeserializeObject<PaymentResponse>(response); }