1
+ using Microsoft . AspNetCore . Mvc ;
2
+ using Microsoft . AspNetCore . Mvc . RazorPages ;
3
+ using System . Text . Json ;
4
+
5
+ namespace aspnetcore_example . Pages ;
6
+
7
+ public class IndexModel : PageModel
8
+ {
9
+ private readonly ILogger < IndexModel > _logger ;
10
+
11
+ private string GatewayPageURL ;
12
+
13
+ public IndexModel ( ILogger < IndexModel > logger )
14
+ {
15
+ _logger = logger ;
16
+ }
17
+
18
+ public void OnGet ( )
19
+ {
20
+
21
+ }
22
+
23
+ public RedirectResult OnPost ( )
24
+ {
25
+ var baseUrl = Request . Scheme + "://" + this . Request . Host ;
26
+ var PostData = new MultipartFormDataContent ( ) ;
27
+
28
+ PostData . Add ( new StringContent ( Request . Form [ "amount" ] ) , "total_amount" ) ;
29
+ PostData . Add ( new StringContent ( "BDT" ) , "currency" ) ;
30
+
31
+ // System Information
32
+ PostData . Add ( new StringContent ( "testbox" ) , "store_id" ) ;
33
+ PostData . Add ( new StringContent ( "qwerty" ) , "store_passwd" ) ;
34
+ PostData . Add ( new StringContent ( "test_tran_001" ) , "tran_id" ) ;
35
+ PostData . Add ( new StringContent ( baseUrl + "/Success" ) , "success_url" ) ;
36
+ PostData . Add ( new StringContent ( baseUrl + "/Fail" ) , "fail_url" ) ; // "Fail.aspx" page needs to be created
37
+ PostData . Add ( new StringContent ( baseUrl + "/Cancel" ) , "cancel_url" ) ; // "Cancel.aspx" page needs to be created
38
+ PostData . Add ( new StringContent ( baseUrl + "/Ipn" ) , "ipn_url" ) ; // Backend IPN needs to be implemented
39
+
40
+ // Customer Information
41
+ PostData . Add ( new StringContent ( "Customer Name" ) , "cus_name" ) ;
42
+ PostData . Add ( new StringContent ( "[email protected] " ) , "cus_email" ) ;
43
+ PostData . Add ( new StringContent ( "Address" ) , "cus_add1" ) ;
44
+ PostData . Add ( new StringContent ( "Dhaka" ) , "cus_city" ) ;
45
+ PostData . Add ( new StringContent ( "1000" ) , "cus_postcode" ) ;
46
+ PostData . Add ( new StringContent ( "Bangladesh" ) , "cus_country" ) ;
47
+ PostData . Add ( new StringContent ( "0111111111" ) , "cus_phone" ) ;
48
+
49
+ // Misc Information
50
+ PostData . Add ( new StringContent ( "NO" ) , "shipping_method" ) ;
51
+ PostData . Add ( new StringContent ( "NO" ) , "num_of_item" ) ;
52
+ PostData . Add ( new StringContent ( "Shoes" ) , "product_category" ) ;
53
+ PostData . Add ( new StringContent ( "Red Shoe" ) , "product_name" ) ;
54
+ PostData . Add ( new StringContent ( "physical-goods" ) , "product_profile" ) ;
55
+ PostData . Add ( new StringContent ( "0" ) , "emi_option" ) ;
56
+
57
+ string ApiUrl = "https://sandbox.sslcommerz.com/gwprocess/v4/api.php" ;
58
+
59
+ var c = new HttpClient ( ) ;
60
+ var wr = new HttpRequestMessage ( HttpMethod . Post , ApiUrl )
61
+ {
62
+ Content = PostData
63
+ } ;
64
+
65
+ var r = c . Send ( wr ) ;
66
+ var response = r . Content . ReadAsStream ( ) ;
67
+
68
+ SSLCommerzInitRes ? res =
69
+ JsonSerializer . Deserialize < SSLCommerzInitRes > ( response ) ;
70
+
71
+ return Redirect ( res ? . GatewayPageURL ) ;
72
+
73
+ }
74
+ }
75
+
76
+ public class SSLCommerzInitRes
77
+ {
78
+ public string status { get ; set ; }
79
+ public string failedreason { get ; set ; }
80
+ public string sessionkey { get ; set ; }
81
+ public Gw gw { get ; set ; }
82
+ public string redirectGatewayURL { get ; set ; }
83
+ public string redirectGatewayURLFailed { get ; set ; }
84
+ public string GatewayPageURL { get ; set ; }
85
+ public string storeBanner { get ; set ; }
86
+ public string storeLogo { get ; set ; }
87
+ public List < Desc > desc { get ; set ; }
88
+ public string is_direct_pay_enable { get ; set ; }
89
+ }
90
+
91
+ public class Gw
92
+ {
93
+ public string visa { get ; set ; }
94
+ public string master { get ; set ; }
95
+ public string amex { get ; set ; }
96
+ public string othercards { get ; set ; }
97
+ public string internetbanking { get ; set ; }
98
+ public string mobilebanking { get ; set ; }
99
+ }
100
+
101
+ public class Desc
102
+ {
103
+ public string name { get ; set ; }
104
+ public string type { get ; set ; }
105
+ public string logo { get ; set ; }
106
+ public string gw { get ; set ; }
107
+ }
0 commit comments