Skip to content

Commit

Permalink
Use correct production or sandbox URL based on configuration mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Jun 21, 2021
1 parent cf7de68 commit 1682638
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/Config.php
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Gateway.php
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/Integration.php
Expand Up @@ -65,7 +65,7 @@ public function setup() {
);

// Notifications controller.
$notifications_controller = new NotificationsController();
$notifications_controller = new NotificationsController( $this );

$notifications_controller->setup();
}
Expand Down
13 changes: 12 additions & 1 deletion src/NotificationsController.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/IntegrationTest.php
Expand Up @@ -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 );

Expand Down

0 comments on commit 1682638

Please sign in to comment.