public async Task MakeMCommercePayment_Throws_Http_Exception_For_Not_Ok_Status_Codes() { var mockHttp = MockHttp.WithStatus(500); var client = new SwishClient(_configuration, mockHttp); await Assert.ThrowsAsync <HttpRequestException>(() => client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel)); }
public async Task <IActionResult> StartMPayment(MPaySwishViewModel model) { if (!ModelState.IsValid) { return(View("MCommmerce")); } // Make payment var mCommercePaymentModel = new MCommercePaymentModel( amount: model.Amount.ToString(), currency: "SEK", callbackUrl: $"{_settings.CallbackBaseUrl}/API/SwishAPI") { PayeePaymentReference = "0123456789", Message = model.Message }; var paymentResponse = await _client.MakeMCommercePaymentAsync(mCommercePaymentModel); if (paymentResponse.IsSuccess) { var paymentFinishedUrl = $"{_settings.CallbackBaseUrl}/Swish/MPaymentCompleted/{paymentResponse.Id}"; var redirectUrl = _client.GenerateSwishUrl(paymentResponse.Token, paymentFinishedUrl); return(Redirect(redirectUrl)); } return(View("SwishError", paymentResponse)); }
public async Task MakeMCommercePaymentAsync_Returns_Correct_ErrorMessage(int status, string message) { var mockHttp = MockHttp.WithStatus(status); var client = new SwishClient(mockHttp, _merchantId); var result = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel); result.ErrorMessage.Should().Contain(message); result.ErrorCode.Should().Be(status.ToString()); }
public async Task MakeMCommercePaymentAsync_Returns_Correct_ErrorMessage_For_422(string errorCode, string errorMessage, string content) { var mockHttp = MockHttp.WithStatusAndContent(422, content); var client = new SwishClient(mockHttp, _merchantId); var result = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel); result.ErrorMessage.Should().Contain(errorMessage); result.ErrorCode.Should().Be(errorCode); }
public async Task MakeMCommercePayment_Throws_Swich_Exception_When_Status_Code_Is_422() { var errorMsg = "Testing error"; var mockHttp = MockHttp.WithStatusAndContent(422, errorMsg); var client = new SwishClient(_configuration, mockHttp); var exception = await Assert.ThrowsAsync <SwishException>(() => client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel)); Assert.Equal(errorMsg, exception.Message); }
//[Fact] public async Task MCommerceScenario() { var clientCert = new X509Certificate2("testcertificates/SwishMerchantTestCertificate1231181189.p12", "swish"); var caCert = new X509Certificate2("testcertificates/TestSwishRootCAv1Test.pem"); var client = new SwishClient(configuration, clientCert, caCert); // Make payment var mcommercePaymentModel = new MCommercePaymentModel( amount: "100", currency: "SEK", callbackUrl: "https://example.com/api/swishcb/paymentrequests") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; var paymentResponse = await client.MakeMCommercePaymentAsync(mcommercePaymentModel); // Wait so that the payment request has been processed Thread.Sleep(5000); // Check payment request status var paymentStatus = await client.GetPaymentStatus(paymentResponse.Id); Assert.Equal("PAID", paymentStatus.Status); // Make refund var refundModel = new RefundModel( originalPaymentReference: paymentStatus.PaymentReference, callbackUrl: "https://example.com/api/swishcb/refunds", payerAlias: "1231181189", amount: "100", currency: "SEK") { PayerPaymentReference = "0123456789", Message = "Refund for Kingston USB Flash Drive 8 GB" };; var refundResponse = await client.MakeRefundAsync(refundModel); // Wait so that the refund request has been processed Thread.Sleep(10000); // Check refund request status var refundStatus = await client.GetRefundStatus(refundResponse.Id); Assert.Equal("PAID", refundStatus.Status); }
public async Task MCommerceScenario() { var client = new SwishClient(SwishEnvironment.Test, _merchantCertificateData, _merchantCertificatePassword, _merchantId); // Make payment var mcommercePaymentModel = new MCommercePaymentModel( amount: "100", currency: "SEK", callbackUrl: "https://example.com/api/swishcb/paymentrequests") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; var paymentResponse = await client.MakeMCommercePaymentAsync(mcommercePaymentModel); // Wait so that the payment request has been processed await Task.Delay(5000); // Check payment request status var paymentStatus = await client.GetPaymentStatus(paymentResponse.Id); Assert.Equal("PAID", paymentStatus.Status); // Make refund var refundModel = new RefundModel( originalPaymentReference: paymentStatus.PaymentReference, callbackUrl: "https://example.com/api/swishcb/refunds", payerAlias: "1231181189", amount: "100", currency: "SEK") { PayerPaymentReference = "0123456789", Message = "Refund for Kingston USB Flash Drive 8 GB" }; var refundResponse = await client.MakeRefundAsync(refundModel); // Wait so that the refund request has been processed await Task.Delay(10000); // Check refund request status var refundStatus = await client.GetRefundStatus(refundResponse.Id); Assert.Equal("PAID", refundStatus.Status); }
public async Task MakeMCommercePayment_Returns_Location_And_Token_Header_VaLues() { string paymentId = "AB23D7406ECE4542A80152D909EF9F6B"; string locationHeader = $"https://mss.swicpc.bankgirot.se/swishcpcapi/v1/paymentrequests/{paymentId}"; var headerValues = new Dictionary <string, string>() { { "Location", locationHeader }, { "PaymentRequestToken", "f34DS34lfd0d03fdDselkfd3ffk21" } }; var responseMessage = Create201HttpJsonResponseMessage(_defaultMCommercePaymentModel, headerValues); var client = new SwishClient(MockHttp.WithResponseMessage(responseMessage), _merchantId); // Act var response = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel); // Assert Assert.Equal(locationHeader, response.Location); Assert.Equal(paymentId, response.Id); Assert.Equal("f34DS34lfd0d03fdDselkfd3ffk21", response.Token); }