66use Pronamic \WordPress \Pay \Banks \BankAccountDetails ;
77use Pronamic \WordPress \Pay \Core \Gateway as Core_Gateway ;
88use Pronamic \WordPress \Pay \Core \PaymentMethods as Core_PaymentMethods ;
9- use Pronamic \WordPress \Pay \Core \Server ;
109use Pronamic \WordPress \Pay \Payments \Payment ;
1110use Pronamic \WordPress \Pay \Payments \PaymentStatus ;
11+ use WP_Error ;
1212
1313/**
1414 * Title: Buckaroo gateway
1515 * Description:
16- * Copyright: 2005-2021 Pronamic
16+ * Copyright: 2005-2022 Pronamic
1717 * Company: Pronamic
1818 *
1919 * @author Remco Tolsma
@@ -50,22 +50,44 @@ public function __construct( Config $config ) {
5050 public function get_issuers () {
5151 $ groups = array ();
5252
53- $ object = $ this ->request ( 'GET ' , 'Transaction/Specification/ideal?serviceVersion=2 ' );
53+ // Check non-empty keys in configuration.
54+ if ( empty ( $ this ->config ->website_key ) || empty ( $ this ->config ->secret_key ) ) {
55+ return $ groups ;
56+ }
57+
58+ // Get iDEAL issuers.
59+ try {
60+ $ object = $ this ->request ( 'GET ' , 'Transaction/Specification/ideal?serviceVersion=2 ' );
61+ } catch ( \Exception $ e ) {
62+ $ this ->set_error ( new WP_Error ( 'buckaroo_error ' , $ e ->getMessage () ) );
63+
64+ return $ groups ;
65+ }
66+
67+ if ( \property_exists ( $ object , 'Actions ' ) ) {
68+ foreach ( $ object ->Actions as $ action ) {
69+ // Check action name.
70+ if ( 'Pay ' !== $ action ->Name ) {
71+ continue ;
72+ }
5473
55- foreach ( $ object ->Actions as $ action ) {
56- if ( 'Pay ' === $ action ->Name ) {
5774 foreach ( $ action ->RequestParameters as $ request_parameter ) {
58- if ( 'issuer ' === $ request_parameter ->Name ) {
59- foreach ( $ request_parameter ->ListItemDescriptions as $ item ) {
60- if ( ! array_key_exists ( $ item ->GroupName , $ groups ) ) {
61- $ groups [ $ item ->GroupName ] = array (
62- 'name ' => $ item ->GroupName ,
63- 'options ' => array (),
64- );
65- }
66-
67- $ groups [ $ item ->GroupName ]['options ' ][ $ item ->Value ] = $ item ->Description ;
75+ // Check request parameter name.
76+ if ( 'issuer ' !== $ request_parameter ->Name ) {
77+ continue ;
78+ }
79+
80+ foreach ( $ request_parameter ->ListItemDescriptions as $ item ) {
81+ // Make sure to add group.
82+ if ( ! array_key_exists ( $ item ->GroupName , $ groups ) ) {
83+ $ groups [ $ item ->GroupName ] = array (
84+ 'name ' => $ item ->GroupName ,
85+ 'options ' => array (),
86+ );
6887 }
88+
89+ // Add issuer to group.
90+ $ groups [ $ item ->GroupName ]['options ' ][ $ item ->Value ] = $ item ->Description ;
6991 }
7092 }
7193 }
@@ -270,11 +292,9 @@ public function start( Payment $payment ) {
270292 * @link https://testcheckout.buckaroo.nl/json/Docs/ResourceModel?modelName=ServicesRequest
271293 * @link https://testcheckout.buckaroo.nl/json/Docs/ResourceModel?modelName=ServiceRequest
272294 */
273- $ payment_method = $ payment ->get_method ();
274-
275- switch ( $ payment_method ) {
295+ switch ( $ payment ->get_payment_method () ) {
276296 /**
277- * Paymet method American Express.
297+ * Payment method American Express.
278298 *
279299 * @link
280300 */
@@ -324,7 +344,7 @@ public function start( Payment $payment ) {
324344 'Parameters ' => array (
325345 array (
326346 'Name ' => 'issuer ' ,
327- 'Value ' => $ payment ->get_issuer ( ),
347+ 'Value ' => $ payment ->get_meta ( ' issuer ' ),
328348 ),
329349 ),
330350 );
@@ -356,7 +376,7 @@ public function start( Payment $payment ) {
356376
357377 break ;
358378 /**
359- * Paymet method Maestro.
379+ * Payment method Maestro.
360380 *
361381 * @link
362382 */
@@ -368,7 +388,7 @@ public function start( Payment $payment ) {
368388
369389 break ;
370390 /**
371- * Paymet method Mastercard.
391+ * Payment method Mastercard.
372392 *
373393 * @link
374394 */
@@ -416,7 +436,7 @@ public function start( Payment $payment ) {
416436
417437 break ;
418438 /**
419- * Paymet method V PAY.
439+ * Payment method V PAY.
420440 *
421441 * @link https://dev.buckaroo.nl/PaymentMethods/Description/creditcards#top
422442 */
@@ -428,7 +448,7 @@ public function start( Payment $payment ) {
428448
429449 break ;
430450 /**
431- * Paymet method Visa.
451+ * Payment method Visa.
432452 *
433453 * @link https://dev.buckaroo.nl/PaymentMethods/Description/creditcards#top
434454 */
@@ -521,6 +541,7 @@ public function start( Payment $payment ) {
521541 * @param string $method HTTP request method.
522542 * @param string $endpoint JSON API endpoint.
523543 * @param object|null $data Data.
544+ * @return object
524545 */
525546 public function request ( $ method , $ endpoint , $ data = null ) {
526547 $ host = 'checkout.buckaroo.nl ' ;
@@ -582,7 +603,20 @@ public function request( $method, $endpoint, $data = null ) {
582603 )
583604 );
584605
585- $ object = $ response ->json ();
606+ try {
607+ $ object = $ response ->json ();
608+ } catch ( \Exception $ e ) {
609+ // JSON error.
610+ $ json_error = \json_last_error ();
611+
612+ // Check authorization error.
613+ if ( \JSON_ERROR_NONE !== $ json_error && 400 === $ response ->status () ) {
614+ throw new \Exception ( $ response ->body () );
615+ }
616+
617+ // Re-throw original response exception.
618+ throw $ e ;
619+ }
586620
587621 /**
588622 * OK.
0 commit comments