Esempio n. 1
0
function gocardless_confirm()
{
    if (isset($_GET['resource_id']) && isset($_GET['resource_type'])) {
        // Get vars found so confirm payment
        // Load GoCardless
        gocardless_init();
        // Params for confirming the resource
        $confirm_params = array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature']);
        // State is optional
        if (isset($_GET['state'])) {
            $confirm_params['state'] = $_GET['state'];
        }
        // Confirm the resource
        $confirmed_resource = GoCardless::confirm_resource($confirm_params);
    }
}
Esempio n. 2
0
function gocardless_admin_update($params = array())
{
    global $gocardless_config;
    global $gocardless_limit;
    // Check form selector is passed
    if (isset($params['form'])) {
        if ($params['form'] == 'config' || $params['form'] == 'limit') {
            // Updating API config
            if ($params['form'] == 'config') {
                $expected_vars = array('app_id', 'app_secret', 'merchant_id', 'access_token', 'sandbox');
                $response = 'API keys updated!';
            }
            // Updating payment info
            if ($params['form'] == 'limit') {
                $expected_vars = array('limit_name', 'limit_description', 'limit_amount', 'limit_interval_length', 'limit_interval_unit', 'limit_calendar_intervals');
                $response = 'Payment updated!';
                $gocardless_limit = $to_save;
            }
            // Loop through expected vars creating array
            foreach ($expected_vars as $key) {
                // Special treatment for checkboxes
                if ($key == 'sandbox' || $key == 'limit_calendar_intervals') {
                    if (isset($_POST[$key]) && $_POST[$key] == 'on') {
                        $to_save[$key] = 'true';
                    } else {
                        $to_save[$key] = false;
                    }
                } else {
                    $to_save[$key] = $_POST[$key];
                }
            }
            // Save with Wordress Options value
            update_option('gocardless_' . $params['form'], $to_save);
            // Run the initialize function again to load vars
            gocardless_init();
        } elseif ($params['form'] == 'cancel') {
            if ($_POST['subscription_id']) {
                // ID found
                // Cancel subscription
                GoCardless_Subscription::find($_POST['subscription_id'])->cancel();
                $response = 'Subscription cancelled!';
            } else {
                // ID not found, fail
                $response = 'Subscription not found!';
            }
        }
        // Return a message
        echo '<div class="updated fade"><p>' . $response . '</p></div>';
    }
}