Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using SwishApi;
  6. using SwishApi.Models;
  7. using Environment = System.Environment;
  8.  
  9. namespace SwishPayout.Pages
  10. {
  11. public class PayoutModel : PageModel
  12. {
  13. [BindProperty]
  14. public string? PayoutTo { get; set; }
  15. [BindProperty]
  16. public string? Personnummer { get; set; }
  17. [BindProperty]
  18. public decimal Amount { get; set; }
  19. [BindProperty]
  20. public string? Message { get; set; }
  21.  
  22. public bool ShowSuccessMessage { get; set; }
  23. public bool ShowErrorMessage { get; set; }
  24. public string CallbackErrorMessage { get; set; } = "";
  25.  
  26. public void OnPost()
  27. {
  28. var clientCertificate = new SwishApi.Models.ClientCertificate()
  29. {
  30. CertificateFilePath = "Cert//Swish_Merchant_TestCertificate_1234679304.pfx",
  31. Password = "swish"
  32. };
  33.  
  34. string certificatePath = Environment.CurrentDirectory + "\\Cert\\Swish_Merchant_TestSigningCertificate_1234679304.pfx";
  35. var payoutClient = new SwishApi.PayoutClient(clientCertificate, "https://eofvqci6optquip.m.pipedream.net", "1234", "1234679304", true, SwishApi.Environment.Emulator);
  36.  
  37. string instructionUUID = Guid.NewGuid().ToString("N").ToUpper();
  38.  
  39. // Anropa MakePayoutRequest med formulärvärden.
  40. var response = payoutClient.MakePayoutRequest(PayoutTo, Personnummer, Amount, Message, instructionUUID, "7d70445ec8ef4d1e3a713427e973d097", new SwishApi.Models.ClientCertificate() { CertificateFilePath = certificatePath, Password = "swish" });
  41.  
  42. if (string.IsNullOrEmpty(response.Error))
  43. {
  44. Console.WriteLine("Location: " + response.Location);
  45.  
  46. // Vänta 5 sekunder så att betalningsförfrågan har behandlats.
  47. System.Threading.Thread.Sleep(5000);
  48.  
  49. // Kontrollera betalningsstatusen.
  50. var statusResponse = payoutClient.CheckPayoutStatus(response.Location);
  51.  
  52. if (string.IsNullOrEmpty(statusResponse.errorCode))
  53. {
  54. // Betalningen har lyckats.
  55. Console.WriteLine("Status: " + statusResponse.status);
  56. ShowSuccessMessage = true;
  57. }
  58. else
  59. {
  60. // Fel vid betalning.
  61. Console.WriteLine("CheckPayoutResponse: " + statusResponse.errorCode + " - " + statusResponse.errorMessage);
  62. ShowErrorMessage = true;
  63. CallbackErrorMessage = statusResponse.errorMessage;
  64. }
  65. }
  66. else
  67. {
  68. // Fel vid betalningsförfrågan.
  69. Console.WriteLine("MakePayoutRequest - ERROR: " + response.Error);
  70. ShowErrorMessage = true;
  71. CallbackErrorMessage = response.Error;
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement