Example #1
0
<?php

/**
 * Moodec DPS Payment Success 
 *
 * @package     local
 * @subpackage  local_moodec
 * @author      Thomas Threadgold
 * @copyright   2015 LearningWorks Ltd
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/local/moodec/lib.php';
require_login();
// This is the result of the transaction from DPS
$data = required_param('result', PARAM_CLEAN);
// We instantiate the cart in order to get the transaction id
$cart = new MoodecCart();
// Then we can set up the gateway using the cart transaction id
$gateway = new MoodecGatewayDPS($cart->get_transaction_id());
// Now handle the data from DPS
$gateway->abort($data);
redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'));
// PERHAPS MAKE CONFIGURABLE?
Example #2
0
<?php

/**
 * Moodec DPS Payment Success 
 *
 * @package     local
 * @subpackage  local_moodec
 * @author      Thomas Threadgold
 * @copyright   2015 LearningWorks Ltd
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/local/moodec/lib.php';
require_login();
// This is the result of the transaction from DPS
$data = required_param('result', PARAM_CLEAN);
// We instantiate the cart in order to get the transaction id
$cart = new MoodecCart();
// Then we can set up the gateway using the cart transaction id
$gateway = new MoodecGatewayDPS($cart->get_transaction_id());
// Now handle the data from DPS
$response = $gateway->handle($data);
// If we successfully handle the data, then redirect
if (!!$response) {
    redirect(new moodle_url($CFG->wwwroot . '/my'));
    // PERHAPS MAKE CONFIGURABLE?
} else {
    print_error('error_enrolfail', 'local_moodec');
}
Example #3
0
<?php

/**
 * Moodec DPS Gateway
 *
 * @package     local
 * @subpackage  local_moodec
 * @author      Thomas Threadgold
 * @copyright   2015 LearningWorks Ltd
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/local/moodec/lib.php';
$transactionID = required_param('id', PARAM_INT);
// plugin instance id
require_login();
$transaction = new MoodecTransaction($transactionID);
// If the transaction is already completed, we do not want to do it again
if ($transaction->get_status() === MoodecTransaction::STATUS_COMPLETE) {
    redirect(new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'));
}
$gateway = new MoodecGatewayDPS($transaction);
$response = $gateway->begin();
// abort if DPS returns an invalid response
if ($response->attributes()->valid != '1') {
    print_error('error_dpsinitiate', 'local_moodec');
} else {
    // otherwise, redirect to the DPS provided URI
    redirect($response->URI);
}
Example #4
0
 /**
  * Returns the HTML for the Moodec cart review on the checkout page
  * @param 	array 		cart
  * @param 	bool 		is it the checkout page
  * @return 	string 		the HTML output
  */
 function cart_review($cart, $removedProducts = array())
 {
     global $CFG, $USER;
     // Require Moodec lib
     require_once $CFG->dirroot . '/local/moodec/lib.php';
     // OPEN cart-overview
     $html = '<div class="cart-overview">';
     // Output cart review message
     $html .= sprintf('<p class="cart-review__message">%s</p>', get_string('checkout_message', 'local_moodec'));
     if (!!$removedProducts && is_array($removedProducts)) {
         $html .= '<div class="cart-review__wrapper">';
         $html .= sprintf('<p class="cart-review__message--removed">%s</p>', get_string('checkout_removed_courses_label', 'local_moodec'));
         $html .= '<ul>';
         foreach ($removedProducts as $p) {
             $thisProduct = local_moodec_get_product($p);
             $html .= sprintf('<li class="cart-review__item--removed">%s</li>', $thisProduct->get_fullname());
         }
         $html .= '</ul></div>';
     }
     if ($cart->is_empty() === false) {
         $html .= '<ul class="products">';
         // Go through each product in the cart
         foreach ($cart->get() as $pID => $vID) {
             $product = local_moodec_get_product($pID);
             $html .= '<li class="product-item">';
             // Product title and variation
             $html .= sprintf('<h4 class="product-title"><a href="%s">%s</a></h4>', new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array('id' => $product->get_id())), $product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_fullname() : $product->get_fullname() . ' - ' . $product->get_variation($vID)->get_name());
             // Product price
             $html .= sprintf('<div class="product-price">%s%.02f</div>', local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')), $product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_price() : $product->get_variation($vID)->get_price());
             $html .= '</li>';
         }
         $html .= '</ul>';
         // Output cart summary section
         $html .= '<div class="cart-summary">';
         // Cart total price
         $html .= sprintf('<h3 class="cart-total__label">%s</h3><h3 class="cart-total">%s%01.2f</h3>', get_string('cart_total', 'local_moodec'), local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')), $cart->get_total(false));
         $html .= '</div>';
         // Return to store button
         $html .= $this->return_to_store_action();
         // Render all active Gateway options
         if (!!get_config('local_moodec', 'payment_dps_enable')) {
             $gatewayDPS = new MoodecGatewayDPS($cart->get_transaction_id());
             $html .= $gatewayDPS->render();
         }
         if (!!get_config('local_moodec', 'payment_paypal_enable')) {
             $gatewayPaypal = new MoodecGatewayPaypal($cart->get_transaction_id());
             $html .= $gatewayPaypal->render();
         }
     } else {
         // Empty cart message
         $html .= sprintf('<p class="cart-mesage--empty">%s</p>', get_string('cart_empty_message', 'local_moodec'));
         // Return to store button
         $html .= $this->return_to_store_action();
     }
     // CLOSE cart-overview
     $html .= '</div>';
     return $html;
 }