public async Task <ActionResult> Swish(FormCollection f) { string payeePaymentReference = f["inputReference"]; string payerAlias = f["inputBuyerNumber"]; int amount = Convert.ToInt32(f["inputAmountr"]); string message = f["inputMessage"]; var client = GetSwishClient(); // Make payment var ecommercePaymentModel = new ECommercePaymentModel( amount: amount.ToString(), currency: "SEK", callbackUrl: Config.Test.CallbackURL, payerAlias: payerAlias) { PayeePaymentReference = payeePaymentReference, Message = message }; var paymentResponse = await client.MakeECommercePaymentAsync(ecommercePaymentModel); ViewBag.result = paymentResponse; return(View()); }
public SwishClientTests() { _defaultECommercePaymentModel = new ECommercePaymentModel( amount: "100", callbackUrl: "https://example.com/api/swishcb/paymentrequests", currency: "SEK", payerAlias: "467012345678") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; _defaultMCommercePaymentModel = new MCommercePaymentModel( amount: "100", callbackUrl: "https://example.com/api/swishcb/paymentrequests", currency: "SEK") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; _defaultRefund = new RefundModel( originalPaymentReference: "6D6CD7406ECE4542A80152D909EF9F6B", callbackUrl: "https://example.com/api/swishcb/refunds", payerAlias: "1231181189", amount: "100", currency: "SEK") { PayerPaymentReference = "0123456789", Message = "Refund for Kingston USB Flash Drive 8 GB" }; }
public async Task <IActionResult> StartEPayment(EPaySwishViewModel model) { if (!ModelState.IsValid) { return(View("ECommerce")); } // Make payment var ecommercePaymentModel = new ECommercePaymentModel( amount: model.Amount.ToString(), currency: "SEK", callbackUrl: $"{_settings.CallbackBaseUrl}/API/SwishAPI", payerAlias: model.PhoneNumber) { PayeePaymentReference = "0123456789", Message = model.Message }; //swish://paymentrequest?token=<token>&callbackurl=<callbackURL> var paymentResponse = await _client.MakeECommercePaymentAsync(ecommercePaymentModel); if (paymentResponse.IsSuccess) { return(View(paymentResponse)); } return(View("SwishError", paymentResponse)); }
public async Task ECommerceScenario() { var clientCert = new X509Certificate2("testcertificates/SwishMerchantTestCertificate1231181189.p12", "swish"); var caCert = new X509Certificate2("testcertificates/Swish TLS Root CA.pem"); var client = new SwishClient(configuration, clientCert, caCert); // Make payment var ecommercePaymentModel = new ECommercePaymentModel( amount: "100", currency: "SEK", callbackUrl: "https://example.com/api/swishcb/paymentrequests", payerAlias: "1231234567890") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; var paymentResponse = await client.MakeECommercePaymentAsync(ecommercePaymentModel); Console.WriteLine("Hello"); // 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 ECommerceScenario() { var client = new SwishClient(SwishEnvironment.Test, _merchantCertificateData, _merchantCertificatePassword, _merchantId); // Make payment var ecommercePaymentModel = new ECommercePaymentModel( amount: "100", currency: "SEK", callbackUrl: "https://example.com/api/swishcb/paymentrequests", payerAlias: "1231234567890") { PayeePaymentReference = "0123456789", Message = "Kingston USB Flash Drive 8 GB" }; var paymentResponse = await client.MakeECommercePaymentAsync(ecommercePaymentModel); // 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); }