MDL-70287 core_payment: Redirect user to the successurl after payment
authorShamim Rezaie <shamim@moodle.com>
Thu, 3 Dec 2020 08:08:32 +0000 (19:08 +1100)
committerShamim Rezaie <shamim@moodle.com>
Wed, 24 Feb 2021 11:44:10 +0000 (22:44 +1100)
enrol/fee/classes/plugin.php
enrol/fee/templates/payment_region.mustache
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

index 549247c..68170c7 100644 (file)
@@ -212,6 +212,7 @@ class enrol_fee_plugin extends enrol_plugin {
                 'instanceid' => $instance->id,
                 'description' => get_string('purchasedescription', 'enrol_fee',
                     format_string($course->fullname, true, ['context' => $context])),
+                'successurl' => \enrol_fee\payment\service_provider::get_success_url('fee', $instance->id)->out(false),
             ];
             echo $OUTPUT->render_from_template('enrol_fee/payment_region', $data);
         }
index b8947aa..7123554 100644 (file)
     * data-itemid
     * data-cost
     * data-description
+    * data-successurl
 
     Context variables required for this template:
     * cost - Human readable cost string including amount and currency
     * instanceid - Id of the enrolment instance
     * description - The description for this purchase
+    * successurl - The URL of the course
 
     Example context (json):
     {
         "cost": "$108.50",
         "instanceid": 11,
         "description": "Enrolment in course Introduction to algorithms",
+        "successurl": "https://moodlesite/course/view.php?id=2",
         "isguestuser": false
     }
 
@@ -63,6 +66,7 @@
             data-paymentarea="fee"
             data-itemid="{{instanceid}}"
             data-cost="{{cost}}"
+            data-successurl="{{successurl}}"
             data-description={{# quote }}{{description}}{{/ quote }}
         >
             {{# str }} sendpaymentbutton, enrol_fee {{/ str }}
index 3cda810..80961db 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js and b/payment/amd/build/gateways_modal.min.js differ
index d215e53..0c97f11 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 5d07448..2981e84 100644 (file)
@@ -95,7 +95,7 @@ const show = async(rootNode, {
                     message: message,
                     type: 'success',
                 });
-                location.reload();
+                location.href = rootNode.dataset.successurl;
 
                 // The following return statement is never reached. It is put here just to make eslint happy.
                 return message;
index 43a2057..e10721c 100644 (file)
@@ -141,8 +141,8 @@ class helper {
     /**
      * Returns the attributes to place on a pay button.
      *
-     * @param string $component Name of the component that the itemid belongs to
-     * @param string $paymentarea
+     * @param string $component Name of the component that the paymentarea and itemid belong to
+     * @param string $paymentarea Payment area
      * @param int $itemid An internal identifier that is used by the component
      * @param string $description Description of the payment
      * @return array
@@ -151,6 +151,7 @@ class helper {
             string $description): array {
 
         $payable = static::get_payable($component, $paymentarea, $itemid);
+        $successurl = static::get_success_url($component, $paymentarea, $itemid);
 
         return [
             'id' => 'gateways-modal-trigger',
@@ -161,6 +162,7 @@ class helper {
             'data-itemid' => $itemid,
             'data-cost' => static::get_cost_as_string($payable->get_amount(), $payable->get_currency()),
             'data-description' => $description,
+            'data-successurl' => $successurl->out(false),
         ];
     }