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 GenerateSwishUrl_Returns_Valid_Url() { // Arrange var token = "c28a4061470f4af48973bd2a4642b4fa"; var redirectUrl = "https://example.com/api/swishcb/mpaymentcomplete/123"; var client = new SwishClient(null, _merchantId); // Act string result = client.GenerateSwishUrl(token, redirectUrl); // Assert result.Should().MatchEquivalentOf("swish://paymentrequest?token=*&callbackurl=*"); result.Should().Contain(token); result.Should().Contain(WebUtility.UrlEncode(redirectUrl)); }