1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Threading . Tasks ;
4
+ using MangoPay . SDK . Core . Enumerations ;
5
+ using MangoPay . SDK . Entities ;
6
+ using MangoPay . SDK . Entities . GET ;
7
+ using MangoPay . SDK . Entities . PUT ;
8
+ using NUnit . Framework ;
9
+
10
+ namespace MangoPay . SDK . Tests
11
+ {
12
+ [ TestFixture ]
13
+ [ Explicit ]
14
+ public class ApiRecipientsTest : BaseTest
15
+ {
16
+ private static RecipientDTO _recipient ;
17
+
18
+ [ Test ]
19
+ public async Task Test_CreateRecipient ( )
20
+ {
21
+ await GetNewRecipient ( ) ;
22
+
23
+ Assert . IsNotNull ( _recipient ) ;
24
+ Assert . IsNotNull ( _recipient . Status ) ;
25
+ Assert . IsNotNull ( _recipient . DisplayName ) ;
26
+ Assert . IsNotNull ( _recipient . PayoutMethodType ) ;
27
+ Assert . IsNotNull ( _recipient . RecipientType ) ;
28
+ Assert . IsNotNull ( _recipient . RecipientScope ) ;
29
+ Assert . IsNotNull ( _recipient . UserId ) ;
30
+ Assert . IsNotNull ( _recipient . IndividualRecipient ) ;
31
+ Assert . IsNotNull ( _recipient . LocalBankTransfer ) ;
32
+ Assert . IsNotNull ( _recipient . LocalBankTransfer [ "GBP" ] . SortCode ) ;
33
+ Assert . IsNotNull ( _recipient . LocalBankTransfer [ "GBP" ] . AccountNumber ) ;
34
+ Assert . IsNotNull ( _recipient . PendingUserAction ) ;
35
+ }
36
+
37
+ [ Test ]
38
+ public async Task Test_GetRecipient ( )
39
+ {
40
+ await GetNewRecipient ( ) ;
41
+ RecipientDTO fetched = await Api . Recipients . GetAsync ( _recipient . Id ) ;
42
+ Assert . IsNotNull ( fetched ) ;
43
+ Assert . AreEqual ( _recipient . Id , fetched . Id ) ;
44
+ Assert . AreEqual ( _recipient . Status , fetched . Status ) ;
45
+ }
46
+
47
+ [ Test ]
48
+ public async Task Test_GetUserRecipients ( )
49
+ {
50
+ await GetNewRecipient ( ) ;
51
+ UserNaturalScaDTO john = await GetJohnScaOwner ( ) ;
52
+ ListPaginated < RecipientDTO > recipients = await Api . Recipients . GetUserRecipientsAsync ( john . Id ) ;
53
+ Assert . IsNotEmpty ( recipients ) ;
54
+ }
55
+
56
+ [ Test ]
57
+ public async Task Test_GetPayoutMethods ( )
58
+ {
59
+ PayoutMethods payoutMethods = await Api . Recipients . GetPayoutMethodsAsync ( CountryIso . DE , CurrencyIso . EUR ) ;
60
+ Assert . IsNotNull ( payoutMethods ) ;
61
+ Assert . IsNotEmpty ( payoutMethods . AvailablePayoutMethods ) ;
62
+ }
63
+
64
+ [ Test ]
65
+ public async Task Test_GetSchema_LocalBankTransfer_Individual ( )
66
+ {
67
+ RecipientSchemaDTO schema =
68
+ await Api . Recipients . GetSchemaAsync ( "LocalBankTransfer" , "Individual" ,
69
+ CurrencyIso . GBP ) ;
70
+ Assert . IsNotNull ( schema ) ;
71
+ Assert . IsNotNull ( schema . DisplayName ) ;
72
+ Assert . IsNotNull ( schema . Currency ) ;
73
+ Assert . IsNotNull ( schema . RecipientType ) ;
74
+ Assert . IsNotNull ( schema . PayoutMethodType ) ;
75
+ Assert . IsNotNull ( schema . RecipientScope ) ;
76
+ Assert . IsNotNull ( schema . Tag ) ;
77
+ Assert . IsNotNull ( schema . LocalBankTransfer ) ;
78
+ Assert . IsNotNull ( schema . IndividualRecipient ) ;
79
+ Assert . IsNull ( schema . InternationalBankTransfer ) ;
80
+ Assert . IsNull ( schema . BusinessRecipient ) ;
81
+ }
82
+
83
+ [ Test ]
84
+ public async Task Test_GetSchema_InternationalBankTransfer_Business ( )
85
+ {
86
+ RecipientSchemaDTO schema =
87
+ await Api . Recipients . GetSchemaAsync ( "InternationalBankTransfer" , "Business" ,
88
+ CurrencyIso . GBP ) ;
89
+ Assert . IsNotNull ( schema ) ;
90
+ Assert . IsNotNull ( schema . DisplayName ) ;
91
+ Assert . IsNotNull ( schema . Currency ) ;
92
+ Assert . IsNotNull ( schema . RecipientType ) ;
93
+ Assert . IsNotNull ( schema . PayoutMethodType ) ;
94
+ Assert . IsNotNull ( schema . RecipientScope ) ;
95
+ Assert . IsNotNull ( schema . Tag ) ;
96
+ Assert . IsNotNull ( schema . InternationalBankTransfer ) ;
97
+ Assert . IsNotNull ( schema . BusinessRecipient ) ;
98
+ Assert . IsNull ( schema . LocalBankTransfer ) ;
99
+ Assert . IsNull ( schema . IndividualRecipient ) ;
100
+ }
101
+
102
+ [ Test ]
103
+ public async Task Test_ValidateRecipient ( )
104
+ {
105
+ RecipientPostDTO postDto = GetPostDto ( ) ;
106
+ UserNaturalScaDTO john = await GetJohnScaOwner ( ) ;
107
+ // should pass
108
+ await Api . Recipients . ValidateAsync ( postDto , john . Id ) ;
109
+
110
+ // should fail
111
+ postDto . DisplayName = null ;
112
+ try
113
+ {
114
+ await Api . Recipients . ValidateAsync ( postDto , john . Id ) ;
115
+ }
116
+ catch ( Exception e )
117
+ {
118
+ Assert . True ( e . Message . Contains ( "One or several required parameters are missing or incorrect" ) ) ;
119
+ }
120
+ }
121
+
122
+ [ Test ]
123
+ [ Ignore ( "The recipient needs to be manually activated before running the test" ) ]
124
+ public async Task Test_DeactivateRecipient ( )
125
+ {
126
+ await GetNewRecipient ( ) ;
127
+ Assert . AreEqual ( "PENDING" , _recipient . Status ) ;
128
+ RecipientPutDTO putDto = new RecipientPutDTO ( ) { Status = "DEACTIVATED" } ;
129
+
130
+ RecipientDTO deactivated = await Api . Recipients . DeactivateAsync ( putDto , _recipient . Id ) ;
131
+ RecipientDTO fetched = await Api . Recipients . GetAsync ( _recipient . Id ) ;
132
+ Assert . AreEqual ( "DEACTIVATED" , deactivated . Status ) ;
133
+ Assert . AreEqual ( "DEACTIVATED" , fetched . Status ) ;
134
+ }
135
+
136
+ private async Task GetNewRecipient ( )
137
+ {
138
+ if ( _recipient == null )
139
+ {
140
+ UserNaturalScaDTO john = await GetJohnScaOwner ( ) ;
141
+ RecipientPostDTO postDto = GetPostDto ( ) ;
142
+ _recipient = await Api . Recipients . CreateAsync ( postDto , john . Id ) ;
143
+ }
144
+ }
145
+
146
+ private RecipientPostDTO GetPostDto ( )
147
+ {
148
+ RecipientPostDTO postDto = new RecipientPostDTO ( ) ;
149
+
150
+ Dictionary < string , object > localBankTransfer = new Dictionary < string , object > ( ) ;
151
+ Dictionary < string , object > gbpDetails = new Dictionary < string , object > ( ) ;
152
+ gbpDetails . Add ( "SortCode" , "010039" ) ;
153
+ gbpDetails . Add ( "AccountNumber" , "11696419" ) ;
154
+ localBankTransfer . Add ( CurrencyIso . GBP . ToString ( ) , gbpDetails ) ;
155
+
156
+ postDto . DisplayName = "My DB account" ;
157
+ postDto . PayoutMethodType = "LocalBankTransfer" ;
158
+ postDto . RecipientType = "Individual" ;
159
+ postDto . Currency = CurrencyIso . GBP ;
160
+ postDto . IndividualRecipient = new IndividualRecipient ( )
161
+ {
162
+ FirstName = "Payout" ,
163
+ LastName = "Team" ,
164
+ Address = new Address
165
+ {
166
+ AddressLine1 = "Address line 1" ,
167
+ AddressLine2 = "Address line 2" ,
168
+ City = "Paris" ,
169
+ Country = CountryIso . FR ,
170
+ PostalCode = "11222" ,
171
+ Region = "Paris"
172
+ }
173
+ } ;
174
+ postDto . LocalBankTransfer = localBankTransfer ;
175
+
176
+ return postDto ;
177
+ }
178
+ }
179
+ }
0 commit comments