コード例 #1
0
ファイル: Utils.php プロジェクト: siparker/gocardless-whmcs
 /**
  * Generates, encodes, re-orders variables for the query string.
  *
  * @param array $params The specific parameters for this payment
  * @param array $pairs Pairs
  * @param string $namespace The namespace
  *
  * @return string An encoded string of parameters
  */
 public static function generate_query_string($params, &$pairs = array(), $namespace = null)
 {
     if (is_array($params)) {
         foreach ($params as $k => $v) {
             if (is_int($k)) {
                 GoCardless_Utils::generate_query_string($v, $pairs, $namespace . '[]');
             } else {
                 GoCardless_Utils::generate_query_string($v, $pairs, $namespace !== null ? $namespace . "[{$k}]" : $k);
             }
         }
         if ($namespace !== null) {
             return $pairs;
         }
         if (empty($pairs)) {
             return '';
         }
         usort($pairs, array(__CLASS__, 'sortPairs'));
         $strs = array();
         foreach ($pairs as $pair) {
             $strs[] = $pair[0] . '=' . $pair[1];
         }
         return implode('&', $strs);
     } else {
         $pairs[] = array(rawurlencode($namespace), rawurlencode($params));
     }
 }
コード例 #2
0
ファイル: Client.php プロジェクト: siparker/gocardless-whmcs
 /**
  * Generate a new payment url
  *
  * @param string $type Payment type
  * @param string $params The specific parameters for this payment
  *
  * @return string The new payment URL
  */
 public function new_limit_url($type, $params)
 {
     // $params are passed in
     // Optional $params are saved in $request and removed from $params
     // $params now only contains params for the payments
     // $payment_params is created containing sub-object named after $type
     // Merge $payment_params, $request and mandatory params
     // Sign
     // Generate query string
     // Return resulting url
     // Declare empty array
     $request = array();
     // Add in merchant id
     $params['merchant_id'] = $this->account_details['merchant_id'];
     // Define optional parameters
     $opt_params = array('redirect_uri', 'cancel_uri', 'state');
     // Loop through optional parameters
     foreach ($opt_params as $opt_param) {
         if (isset($params[$opt_param])) {
             $request[$opt_param] = $params[$opt_param];
             unset($params[$opt_param]);
         }
     }
     // If no method-specific redirect submitted then
     // use class level if available
     if (!isset($request['redirect_uri']) && isset($this->redirect_uri)) {
         $request['redirect_uri'] = $this->redirect_uri;
     }
     // Create array of payment params
     $payment_params = array($type => $params);
     // Put together all the bits: passed params inc payment params & mandatory
     $request = array_merge($request, $payment_params, $this->generate_mandatory_params());
     // Generate signature
     $request['signature'] = GoCardless_Utils::generate_signature($request, $this->account_details['app_secret']);
     // Generate query string from all parameters
     $query_string = GoCardless_Utils::generate_query_string($request);
     // Generate url NB. Pluralises resource
     return $this->base_url . '/connect/' . $type . 's/new?' . $query_string;
 }