@@ -253,6 +253,77 @@ def test_successful_inquire
253253 assert response . test?
254254 end
255255
256+ def test_successful_transaction_search
257+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search' , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
258+
259+ assert response = @gateway . transaction_search
260+ assert_success response
261+ assert_equal 2 , response . params [ 'response' ] . length
262+ assert_equal 'ch_Kw_JxmVqMeSOQU19_krRdw' , response . params [ 'response' ] [ 0 ] [ 'token' ]
263+ assert response . test?
264+ end
265+
266+ def test_transaction_search_with_query
267+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search?query=roland%40pinpayments.com' , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
268+
269+ assert response = @gateway . transaction_search ( query : 'roland@pinpayments.com' )
270+ assert_success response
271+ assert_equal 2 , response . params [ 'response' ] . length
272+ assert response . test?
273+ end
274+
275+ def test_transaction_search_with_date_range
276+ start_date = '2025-01-01'
277+ end_date = '2025-01-31'
278+ @gateway . expects ( :ssl_request ) . with ( :get , "https://test-api.pinpayments.com/1/charges/search?end_date=#{ end_date } &start_date=#{ start_date } " , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
279+
280+ assert response = @gateway . transaction_search ( start_date : start_date , end_date : end_date )
281+ assert_success response
282+ assert response . test?
283+ end
284+
285+ def test_transaction_search_with_pagination
286+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search?page=2' , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
287+
288+ assert response = @gateway . transaction_search ( page : 2 )
289+ assert_success response
290+ assert response . test?
291+ end
292+
293+ def test_transaction_search_with_sort_and_direction
294+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search?direction=1&sort=created_at' , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
295+
296+ assert response = @gateway . transaction_search ( sort : 'created_at' , direction : 1 )
297+ assert_success response
298+ assert response . test?
299+ end
300+
301+ def test_transaction_search_with_amount_sort
302+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search?direction=-1&sort=amount' , nil , instance_of ( Hash ) ) . returns ( successful_transaction_search_response )
303+
304+ assert response = @gateway . transaction_search ( sort : 'amount' , direction : -1 )
305+ assert_success response
306+ assert response . test?
307+ end
308+
309+ def test_transaction_search_empty_results
310+ @gateway . expects ( :ssl_request ) . with ( :get , 'https://test-api.pinpayments.com/1/charges/search' , nil , instance_of ( Hash ) ) . returns ( empty_transaction_search_response )
311+
312+ assert response = @gateway . transaction_search
313+ assert_success response
314+ assert_equal 0 , response . params [ 'response' ] . length
315+ assert response . test?
316+ end
317+
318+ def test_unsuccessful_transaction_search
319+ @gateway . expects ( :ssl_request ) . returns ( failed_transaction_search_response )
320+
321+ assert response = @gateway . transaction_search
322+ assert_failure response
323+ assert_equal 'The requested resource could not be found.' , response . message
324+ assert response . test?
325+ end
326+
256327 def test_successful_refund
257328 token = 'ch_encBuMDf17qTabmVjDsQlg'
258329 @gateway . expects ( :ssl_request ) . with ( :post , "https://test-api.pinpayments.com/1/charges/#{ token } /refunds" , { amount : '100' } . to_json , instance_of ( Hash ) ) . returns ( successful_refund_response )
@@ -800,6 +871,96 @@ def successful_inquire_response
800871 }'
801872 end
802873
874+ def successful_transaction_search_response
875+ '{
876+ "response": [
877+ {
878+ "token": "ch_Kw_JxmVqMeSOQU19_krRdw",
879+ "success": true,
880+ "amount": 400,
881+ "currency": "AUD",
882+ "description": "test charge",
883+ "email": "roland@pinpayments.com",
884+ "ip_address": "203.192.1.172",
885+ "created_at": "2025-01-14T03:00:41Z",
886+ "status_message": "Success!",
887+ "error_message": null,
888+ "card": {
889+ "token": "card_0oG1hjachN7g8KsOnWlOcg",
890+ "display_number": "XXXX-XXXX-XXXX-0000",
891+ "scheme": "master",
892+ "address_line1": "42 Sevenoaks St",
893+ "address_line2": null,
894+ "address_city": "Lathlain",
895+ "address_postcode": "6454",
896+ "address_state": "WA",
897+ "address_country": "AU"
898+ },
899+ "transfer": [],
900+ "amount_refunded": 0,
901+ "total_fees": 62,
902+ "merchant_entitlement": 338,
903+ "refund_pending": false,
904+ "captured": true,
905+ "captured_at": "2025-01-14T03:00:41Z"
906+ },
907+ {
908+ "token": "ch_ABC123XYZ",
909+ "success": true,
910+ "amount": 200,
911+ "currency": "AUD",
912+ "description": "another test charge",
913+ "email": "roland@pinpayments.com",
914+ "ip_address": "203.192.1.173",
915+ "created_at": "2025-01-15T04:00:41Z",
916+ "status_message": "Success!",
917+ "error_message": null,
918+ "card": {
919+ "token": "card_ABC123",
920+ "display_number": "XXXX-XXXX-XXXX-1111",
921+ "scheme": "visa"
922+ },
923+ "transfer": [],
924+ "amount_refunded": 0,
925+ "total_fees": 32,
926+ "merchant_entitlement": 168,
927+ "refund_pending": false,
928+ "captured": true,
929+ "captured_at": "2025-01-15T04:00:41Z"
930+ }
931+ ],
932+ "pagination": {
933+ "current": 1,
934+ "previous": null,
935+ "next": null,
936+ "per_page": 25,
937+ "pages": 1,
938+ "count": 2
939+ }
940+ }'
941+ end
942+
943+ def empty_transaction_search_response
944+ '{
945+ "response": [],
946+ "pagination": {
947+ "current": 1,
948+ "previous": null,
949+ "next": null,
950+ "per_page": 25,
951+ "pages": 0,
952+ "count": 0
953+ }
954+ }'
955+ end
956+
957+ def failed_transaction_search_response
958+ '{
959+ "error": "not_found",
960+ "error_description": "The requested resource could not be found."
961+ }'
962+ end
963+
803964 def successful_refund_response
804965 '{
805966 "response":{
0 commit comments