diff --git a/src/Config.php b/src/Config.php index eca3fc0..6976948 100644 --- a/src/Config.php +++ b/src/Config.php @@ -47,6 +47,34 @@ public function get_email() { return $this->email; } + /** + * Get the `webscr` URL. + * + * @link https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/formbasics/ + * @return string + */ + public function get_webscr_url() { + if ( 'test' === $this->mode ) { + return 'https://www.sandbox.paypal.com/cgi-bin/webscr'; + } + + return 'https://www.paypal.com/cgi-bin/webscr'; + } + + /** + * Get the IPN post back URL. + * + * @link https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNImplementation/#specs + * @return string + */ + public function get_ipn_pb_url() { + if ( 'test' === $this->mode ) { + return 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; + } + + return 'https://ipnpb.paypal.com/cgi-bin/webscr'; + } + /** * JSON serialize. * diff --git a/src/Gateway.php b/src/Gateway.php index bf79714..75556f9 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -85,7 +85,7 @@ public function start( Payment $payment ) { * @link https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/Appx-websitestandard-htmlvariables/ * @link https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.9.26/includes/gateways/paypal-standard.php */ - $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; + $url = $this->config->get_webscr_url(); $variables = new Variables(); diff --git a/src/Integration.php b/src/Integration.php index bff3f35..f1900af 100644 --- a/src/Integration.php +++ b/src/Integration.php @@ -65,7 +65,7 @@ public function setup() { ); // Notifications controller. - $notifications_controller = new NotificationsController(); + $notifications_controller = new NotificationsController( $this ); $notifications_controller->setup(); } diff --git a/src/NotificationsController.php b/src/NotificationsController.php index 27d97dd..ce9ced7 100644 --- a/src/NotificationsController.php +++ b/src/NotificationsController.php @@ -24,6 +24,15 @@ * @since 1.0.0 */ class NotificationsController { + /** + * Construct notifications controller. + * + * @param Integration $integration Integration. + */ + public function __construct( $integration ) { + $this->integration = $integration; + } + /** * Setup. * @@ -120,13 +129,15 @@ public function rest_api_paypal_ipn( WP_REST_Request $request ) { ); } + $config = $this->integration->get_config( $payment->config_id ); + /** * Instant Payment Notification Post Back URL. * * @link https://developer.paypal.com/docs/api-basics/notifications/ipn/ht-ipn/ * @link https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNImplementation/#specs */ - $ipn_pb_url = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; + $ipn_pb_url = $config->get_ipn_pb_url(); /** * Prefix the returned message with the `cmd=_notify-validate` variable, diff --git a/tests/src/IntegrationTest.php b/tests/src/IntegrationTest.php index 506910d..7274291 100644 --- a/tests/src/IntegrationTest.php +++ b/tests/src/IntegrationTest.php @@ -50,7 +50,7 @@ public function test_config_post() { $post_id = $this->factory->post->create(); \update_post_meta( $post_id, '_pronamic_gateway_mode', Gateway::MODE_TEST ); - \update_post_meta( $post_id, '_pronamic_gateway_email', 'info@pronamic.nl' ); + \update_post_meta( $post_id, '_pronamic_gateway_paypal_email', 'info@pronamic.nl' ); $config = $this->integration->get_config( $post_id );