MDL-69166 pg_paypal: Ability to connect to sandbox or live environment
authorShamim Rezaie <shamim@moodle.com>
Fri, 10 Jan 2020 07:59:58 +0000 (18:59 +1100)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 04:44:59 +0000 (15:44 +1100)
payment/gateway/paypal/classes/external/transaction_complete.php
payment/gateway/paypal/lang/en/pg_paypal.php
payment/gateway/paypal/settings.php

index 2569df6..46037a9 100644 (file)
@@ -72,13 +72,14 @@ class transaction_complete extends external_api {
         ]);
 
         $config = get_config('pg_paypal');
+        $sandbox = $config->environment == 'sandbox';
 
         [
             'amount' => $amount,
             'currency' => $currency
         ] = \core_payment\helper::get_cost($component, $componentid);
 
-        $paypalhelper = new paypal_helper($config->clientid, $config->secret, false);
+        $paypalhelper = new \pg_paypal\paypal_helper($config->clientid, $config->secret, $sandbox);
         $authorization = $paypalhelper->capture_authorization($authorizationid, $amount, $currency);
 
         $success = false;
index 9945ae8..81ed8bd 100644 (file)
@@ -28,13 +28,17 @@ $string['captureauthorizationfailed'] = 'Could not capture authorization.';
 $string['clientid'] = 'Client ID';
 $string['clientid_desc'] = 'The client ID that PayPal generated for your application.';
 $string['echecknotsupported'] = 'E-check is not supported.';
+$string['environment'] = 'Environment';
+$string['environment_desc'] = 'You can set this to Sandbox if you are using sandbox accounts (for testing purpose only).';
 $string['gatewaydescription'] = 'PayPal is an authorised payment gateway provider for processing credit card transactions.';
 $string['gatewayname'] = 'PayPal';
 $string['internalerror'] = 'Internal error.';
+$string['live'] = 'Live';
 $string['paymentauthorizationwarning'] = 'For PayPal payment authorizations, you must enable this feature on your PayPal account.';
 $string['paymentnotcleared'] = 'payment not cleared by PayPal.';
 $string['pluginname'] = 'PayPal';
 $string['pluginname_desc'] = 'The PayPal plugin allows you to receive payments via PayPal.';
 $string['repeatedorder'] = 'This order has already been processed earlier.';
+$string['sandbox'] = 'Sandbox';
 $string['secret'] = 'Secret';
 $string['secret_desc'] = 'The secret thatPayPal generated for your application.';
index 1ea9157..4e57615 100644 (file)
@@ -37,4 +37,11 @@ if ($ADMIN->fulltree) {
             get_string('clientid_desc', 'pg_paypal'), '', PARAM_TEXT));
     $settings->add(new admin_setting_configtext('pg_paypal/secret', get_string('secret', 'pg_paypal'),
             get_string('secret_desc', 'pg_paypal'), '', PARAM_TEXT));
+
+    $options = [
+        'live' => get_string('live', 'pg_paypal'),
+        'sandbox'  => get_string('sandbox', 'pg_paypal'),
+    ];
+    $settings->add(new admin_setting_configselect('pg_paypal/environment', get_string('environment', 'pg_paypal'),
+            get_string('environment_desc', 'pg_paypal'), 'live', $options));
 }