MDL-69166 core_payment: send a purchase description to payment gateways
authorShamim Rezaie <shamim@moodle.com>
Mon, 6 Jan 2020 08:54:31 +0000 (19:54 +1100)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 03:37:28 +0000 (14:37 +1100)
We truncate description to 127 chars as per PayPal requirement

payment/amd/build/gateways_modal.min.js
payment/amd/build/gateways_modal.min.js.map
payment/amd/src/gateways_modal.js
payment/classes/helper.php
payment/gateway/paypal/amd/build/gateways_modal.min.js
payment/gateway/paypal/amd/build/gateways_modal.min.js.map
payment/gateway/paypal/amd/src/gateways_modal.js

index 3660ca7..f69ff04 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js and b/payment/amd/build/gateways_modal.min.js differ
index 034b0fd..a2b8d63 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js.map and b/payment/amd/build/gateways_modal.min.js.map differ
index a95c797..0424017 100644 (file)
@@ -95,20 +95,21 @@ const show = (rootNode, {
                 const root = modal.getRoot()[0];
                 const gateway = (root.querySelector(Selectors.values.gateway) || {value: ''}).value;
 
-                if (gateway) {
-                    processPayment(
-                        root,
-                        gateway,
-                        rootNode.dataset.amount,
-                        rootNode.dataset.currency,
-                        rootNode.dataset.component,
-                        rootNode.dataset.componentid
-                    );
-                } else {
-                    getString('nogatewayselected', 'core_payment').then(message => {
-                        return addToast(message);
-                    });
-                }
+                        if (gateway) {
+                            processPayment(
+                                root,
+                                gateway,
+                                rootNode.dataset.amount,
+                                rootNode.dataset.currency,
+                                rootNode.dataset.component,
+                                rootNode.dataset.componentid,
+                                rootNode.dataset.description,
+                            );
+                        } else {
+                            getString('nogatewayselected', 'core_payment').then(message => {
+                                return addToast(message);
+                            });
+                        }
 
                 e.preventDefault();
             });
@@ -127,10 +128,11 @@ const show = (rootNode, {
  * @param {string} currency The currency in the three-character ISO-4217 format
  * @param {string} component Name of the component that the componentid belongs to
  * @param {number} componentid An internal identifier that is used by the component
+ * @param {string} description Description of the payment
  * @returns {Promise<void>}
  */
-const processPayment = async(rootElement, gateway, amount, currency, component, componentid) => {
+const processPayment = async(rootElement, gateway, amount, currency, component, componentid, description) => {
     const paymentMethod = await import(`pg_${gateway}/gateways_modal`);
 
-    paymentMethod.process(rootElement, amount, currency, component, componentid);
+    paymentMethod.process(rootElement, amount, currency, component, componentid, description);
 };
index ef9df49..6c4d631 100644 (file)
@@ -96,9 +96,13 @@ class helper {
      *
      * @param float $amount Amount of payment
      * @param string $currency Currency of payment
+     * @param string $component Name of the component that the componentid belongs to
+     * @param int $componentid An internal identifier that is used by the component
+     * @param string $description Description of the payment
      * @return array
      */
-    public static function gateways_modal_link_params(float $amount, string $currency, string $component, int $componentid): array {
+    public static function gateways_modal_link_params(float $amount, string $currency, string $component, int $componentid,
+            string $description): array {
         return [
             'id' => 'gateways-modal-trigger',
             'role' => 'button',
@@ -106,6 +110,7 @@ class helper {
             'data-currency' => $currency,
             'data-component' => $component,
             'data-componentid' => $componentid,
+            'data-description' => $description,
         ];
     }
 }
index 0199fd2..1207d27 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/gateways_modal.min.js and b/payment/gateway/paypal/amd/build/gateways_modal.min.js differ
index bd19358..8016a93 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/gateways_modal.min.js.map and b/payment/gateway/paypal/amd/build/gateways_modal.min.js.map differ
index 4fa4269..b84c985 100644 (file)
@@ -37,7 +37,7 @@ const showPlaceholder = async(rootElement) => {
     Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js);
 };
 
-export const process = async(rootElement, amount, currency, component, componentid) => {
+export const process = async(rootElement, amount, currency, component, componentid, description) => {
 
     const [
         ,
@@ -60,7 +60,8 @@ export const process = async(rootElement, amount, currency, component, component
                         amount: {
                             currency_code: currency, // eslint-disable-line
                             value: amount
-                        }
+                        },
+                        description: Truncate.truncate(description, {length: 127, stripTags: true}),
                     }],
                     application_context: { // eslint-disable-line
                         shipping_preference: 'NO_SHIPPING', // eslint-disable-line