Example #1
0
 /**
  * Get a specific subscription
  *
  * @param string $id The id of the subscription to fetch
  *
  * @return object The subscription matching the id requested
  */
 public function subscription($id)
 {
     return GoCardless_Subscription::find_with_client($this, $id);
 }
 public function cancelSubscription($id)
 {
     return \GoCardless_Subscription::find($id)->cancel();
 }
Example #3
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>';
    }
}
Example #4
0
 /**
  * Get a specific subscription
  *
  * @param string $id The id of the subscription to fetch
  *
  * @return object The subscription matching the id requested
  */
 public function subscription($id)
 {
     if (!isset($this->account_details['access_token'])) {
         throw new GoCardless_ClientException('Access token missing');
     }
     return GoCardless_Subscription::find_with_client($this, $id);
 }