/** * The Caller Magic Method */ public function __call($method, $params) { Payment_Utility::load_all_files('vendor/google_checkout/library'); $this->_lib_method = $method; $args = $params[0]; $request = $this->_build_request($args); return $this->_parse_response($request); }
public function __construct($config = array()) { $this->ci =& get_instance(); $this->ci->config->load('payments', true); $defaults = array('mode' => $this->ci->config->item('mode', 'payments'), 'force_secure_connection' => $this->ci->config->item('force_secure_connection', 'payments')); $config = array_merge($defaults, $config); require dirname(__DIR__) . "/src/php-payments/lib/payments.php"; $this->php_payments = new PHP_Payments($config); //Ignore CI classes so our autoloader doesn't interfere Payment_Utility::$autoload_ignore = array('CI_'); }
/** * The Constructor Function */ public function __construct($config) { Payment_Utility::load('file', 'vendor/braintree/lib/Braintree'); $bt_mode = $config['mode'] == 'test' ? 'sandbox' : 'production'; Braintree_Configuration::environment($bt_mode); unset($config['mode']); foreach ($config as $k => $v) { //merchantId, publicKey, privateKey need to be set Braintree_Configuration::$k($v); } }
/** * Make sure params are as expected * * @param array array of params to check to ensure proper formatting * @param array array of required params * @return mixed Will return TRUE if all pass. Will return an object if a param is bad. */ public static function validate($method, $params, $required_params) { //Append _method to method name $method = $method . "_method"; //We'll need this later $lang = Payment_Utility::load('lang', 'english/response_details'); //Ensure no invalid methods were passed include_once 'payment_methods/' . $method . '.php'; $m = new $method(); $method_params = $m->get_params(); $bad_params = array(); foreach ($params as $k => $v) { if (!isset($method_params[$k])) { $bad_params[] = "{$k} " . $lang['is_not_a_param']; } } if (count($bad_params) > 0) { return Payment_Response::instance()->local_response('failure', 'invalid_input', implode(', ', $bad_params)); } //Ensure no required params are missing $missing = array(); foreach ($required_params as $k => $v) { if (!array_key_exists($v, $params) or empty($params[$v]) or is_null($params[$v]) or $params[$v] == ' ') { $key = 'missing_' . $v; if (isset($lang[$key])) { $missing[] = $lang[$key]; } else { error_log("{$key} does not exist in response message language file."); $missing[] = "{$v} is required but was not provided"; } } } if (count($missing) > 0) { return Payment_Response::instance()->local_response('failure', 'required_params_missing', implode(', ', $missing)); } //Ensure dates match MMYYYY format if (array_key_exists('cc_exp', $params)) { $exp_date = $params['cc_exp']; $m1 = $exp_date[0]; if (strlen($exp_date) != 6 or !is_numeric($exp_date) or $m1 > 1) { return Payment_Response::instance()->local_response('failure', 'invalid_input', 'invalid_date_format'); } } //Ensure billing period is submitted in normalized form if (array_key_exists('billing_period', $params)) { $accepted_billing_period = array('Month', 'Day', 'Week', 'Year'); if (!in_array($params['billing_period'], $accepted_billing_period)) { return Payment_Response::instance()->local_response('failure', 'invalid_input', 'invalid_billing_period'); } } return TRUE; }
public function getFields() { $paymentLibrary = $this->paymentlibrary; if ($paymentLibrary->id == PAYMENT_LIBRARY_OMNIPAY) { $fields = Omnipay::create($this->provider)->getDefaultParameters(); } else { $fields = Payment_Utility::load('config', 'drivers/' . strtolower($this->provider)); } if ($fields == null) { $fields = array(); } return $fields; }
/** * Build the Request * * @param array Params array * @return mixed array for requests, strings for buttons */ protected function _build_request($params) { $map = $this->method_map(); $l = $this->_lib_method; $api = $map[$l]['api']; $method = $map[$l]['method']; $static = $map[$l]['static']; if ($api == 'ButtonGenerator') { Payment_Utility::load('file', 'vendor/amazon_simplepay/ButtonGenerationWithSignature/src/ButtonGenerator'); $this->_is_button = true; ob_start(); $api::$method($this->_config['access_key'], $this->_config['secret_key'], $params['currency_code'] . ' ' . $params['amt'], $params['desc'], isset($params['identifier']) ? $params['identifier'] : '', $static['immediate_return'], $static['return_url'], $static['abandon_url'], $static['process_immediate'], $static['ipn_url'], $static['collect_shipping_address'], $static['signature_method'], $this->_mode); $string = ob_get_clean(); return $string; } }
/** * Builds the Request */ protected function _build_request($params) { $stripe = Payment_Utility::load('file', 'vendor/stripe/lib/Stripe'); Stripe::setApiKey($this->_settings['api_key']); $api = $this->_api; if (strpos($this->_api_method, '->') === false) { $method = $this->_api_method; } else { $ex = explode('->', $this->_api_method); $m1 = $ex[0]; $method = $ex[1]; $api = $api::$m1($params['identifier']); $this->_object_scoped = true; } $params_ready = $this->_match_params($params); //Make the call to Stripe API return array($api, $method, $params_ready); }
public function __construct($driver) { $config = array('mode' => 'test'); echo "\n \n Starting test for {$driver} \n \n"; $this->payments = new PHP_Payments($config); $test_config = (include '.drivers.test_vals.php'); $class_name = str_replace('.php', '', $driver); $uc = explode("_", $class_name); foreach ($uc as $k => $piece) { $uc[$k] = ucfirst($piece); } $class_name_uc = implode("_", $uc); $this->class_name = $class_name_uc; $config_name = str_replace('_driver', '', $class_name); $loaded_config = Payment_Utility::load('config', 'drivers/' . $config_name); $this->config = array_merge($config, $test_config); $this->class = new $class_name_uc(array_merge($config, $loaded_config)); $this->methods_available = $this->class->method_map(); }
/** * Make a call to a gateway. Uses other helper methods to make the request. * * @param string The payment method to use * @param array $params[0] is the gateway, $params[1] are the params for the request. $params[2] is a config array for the driver. * @return object Should return a success or failure, along with a response. */ public function __call($method, $params) { $gateway = $params[0] . '_Driver'; $args = $params[1]; $config = isset($params[2]) ? $params[2] : @Payment_Utility::load('config', 'drivers/' . $params[0]); //Load the driver config if not passed in constructor $config['mode'] = isset($this->config['mode']) && $this->config['mode'] === 'test' ? 'test' : 'production'; try { $driver = new $gateway($config); } catch (Exception $e) { return Payment_Response::instance()->local_response('failure', 'not_a_module', $e->getMessage()); } $method_map = $driver->method_map(); if (!isset($method_map[$method])) { return Payment_Response::instance()->local_response('failure', 'not_a_method'); } //Make sure params are in expected format, make sure required have been provided $validation_check = Payment_Validator::validate($method, $args, $method_map[$method]['required']); return $validation_check === true ? $driver->{$method}($args) : $validation_check; }
public function do_payment($invitationKey, $onSite = true) { $rules = array('first_name' => 'required', 'last_name' => 'required', 'card_number' => 'required', 'expiration_month' => 'required', 'expiration_year' => 'required', 'cvv' => 'required', 'address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required'); if ($onSite) { $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('payment/' . $invitationKey)->withErrors($validator); } } $invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail(); $invoice = $invitation->invoice; $accountGateway = $invoice->client->account->account_gateways[0]; $paymentLibrary = $accountGateway->gateway->paymentlibrary; if ($onSite) { $client = $invoice->client; $client->address1 = trim(Input::get('address1')); $client->address2 = trim(Input::get('address2')); $client->city = trim(Input::get('city')); $client->state = trim(Input::get('state')); $client->postal_code = trim(Input::get('postal_code')); $client->save(); } try { if ($paymentLibrary->id == PAYMENT_LIBRARY_OMNIPAY) { $gateway = self::createGateway($accountGateway); $details = self::getPaymentDetails($invoice, Input::all()); $response = $gateway->purchase($details)->send(); $ref = $response->getTransactionReference(); if (!$ref) { Session::flash('error', $response->getMessage()); return Redirect::to('payment/' . $invitationKey)->withInput(); } if ($response->isSuccessful()) { $payment = self::createPayment($invitation, $ref); Session::flash('message', trans('texts.applied_payment')); return Redirect::to('view/' . $payment->invitation->invitation_key); } else { if ($response->isRedirect()) { $invitation->transaction_reference = $ref; $invitation->save(); $response->redirect(); } else { Session::flash('error', $response->getMessage()); return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->getMessage()); } } } else { if ($paymentLibrary->id == PAYMENT_LIBRARY_PHP_PAYMENTS) { $gateway = $accountGateway->gateway; $provider = $gateway->provider; $p = new PHP_Payments(array('mode' => 'test')); $config = Payment_Utility::load('config', 'drivers/' . $provider); switch ($gateway->id) { case GATEWAY_BEANSTREAM: $config['delay_charge'] = FALSE; $config['bill_outstanding'] = TRUE; break; case GATEWAY_AMAZON: $config['return_url'] = URL::to('complete'); $config['abandon_url'] = URL::to('/'); $config['immediate_return'] = 0; $config['process_immediate'] = 1; $config['ipn_url'] = URL::to('ipn'); $config['collect_shipping_address'] = false; break; } $details = self::getPaymentDetails($invoice, Input::all()); $response = $p->oneoff_payment($provider, $details, $config); if (strtolower($response->status) == 'success') { $payment = self::createPayment($invitation, $response->response_message); Session::flash('message', trans('texts.applied_payment')); return Redirect::to('view/' . $payment->invitation->invitation_key); } else { Session::flash('error', $response->response_message); return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->response_message); } } } } catch (\Exception $e) { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage); Utils::logError($e->getMessage()); return Redirect::to('payment/' . $invitationKey)->withInput(); } }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $result = $as_array['Approved']; if (isset($as_array['OrderID']) && !empty($as_array['OrderID'])) { $identifier = $as_array['OrderID']; } if (isset($as_array['TransRefNumber'])) { $identifier2 = $as_array['TransRefNumber']; } $details->timestamp = $as_array['TransTime']; $details->gateway_response = $as_array; if (isset($identifier)) { $identifier = (string) $identifier; if (strlen($identifier) > 1) { $details->identifier = $identifier; } } if (isset($identifier2)) { $identifier2 = (string) $identifier2; if (strlen($identifier2) > 1) { $details->identifier2 = $identifier2; } } if ($result == 'APPROVED') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } if ($result == 'ERROR' or $result == 'DECLINED') { if (isset($as_array['ErrMsg'])) { $message = $as_array['ErrMsg']; $message = explode(':', $message); $message = $message[1]; } if (isset($message)) { $details->reason = $message; } return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
private function __construct() { self::$_response_details = Payment_Utility::load('lang', self::$_language . '/response_details'); self::$_response_messages = Payment_Utility::load('lang', self::$_language . '/response_messages'); self::$_response_codes = Payment_Utility::load('config', 'payments', 'response_codes'); }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { //If it failed when being parsed as XML, go ahead and return it if (isset($xml->status) && $xml->status == 'failure') { return $xml; } $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $result = $as_array['messages']['resultCode']; if (isset($as_array['transactionResponse'])) { $identifier = $as_array['transactionResponse']['transId']; } if (isset($as_array['subscriptionId'])) { $identifier = $as_array['subscriptionId']; } $timestamp = gmdate('c'); $details->timestamp = $timestamp; $details->gateway_response = $as_array; if (isset($identifier) and strlen($identifier) > 1) { $details->identifier = $identifier; } if ($result == 'Ok') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } if ($result == 'Error') { if (isset($as_array['transactionResponse']['errors']['error']['errorText'])) { $message = $as_array['transactionResponse']['errors']['error']['errorText']; } if (isset($as_array['messages']['message']['text'])) { $message = $as_array['messages']['message']['text']; } if (isset($message)) { $details->reason = $message; } return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
/** * Parse the response from the server * * @param array * @return object */ private function _parse_response($response) { $details = (object) array(); if (is_object($response)) { if ($response->code == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response->message; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } elseif (strstr($response, '<response>')) { $response = Payment_Utility::parse_xml($response); $response = Payment_Utility::arrayize_object($response); $details->gateway_response = $response; if ($response['code'] == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response['message']; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } else { $results = explode('&', urldecode($response)); foreach ($results as $result) { list($key, $value) = explode('=', $result); $gateway_response[$key] = $value; } $details->gateway_response = $gateway_response; $details->timestamp = isset($gateway_response['trnDate']) ? $gateway_response['trnDate'] : gmdate('c'); if (isset($gateway_response['trnApproved']) && $gateway_response['trnApproved'] == '1') { $details->identifier = isset($gateway_response['trnId']) ? $gateway_response['trnId'] : null; if (isset($gateway_response['rbAccountId'])) { $details->identifier = $gateway_response['rbAccountId']; } return Payment_Response::instance()->gateway_response('success', $this->_lib_method . '_success', $details); } else { $details->reason = isset($gateway_response['messageText']) ? $gateway_response['messageText'] : null; return Payment_Response::instance()->gateway_response('failure', $this->_lib_method . '_gateway_failure', $details); } } }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $signon = isset($as_array['SignonMsgsRs']) ? $as_array['SignonMsgsRs'] : ''; $response = isset($as_array['QBMSXMLMsgsRs']) ? $as_array['QBMSXMLMsgsRs'] : ''; $result = ''; $message = ''; $identifier = ''; if (isset($response['CustomerCreditCardChargeRs'])) { $result = $response['CustomerCreditCardChargeRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardChargeRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardChargeRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardAuthRs'])) { $result = $response['CustomerCreditCardAuthRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardAuthRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardAuthRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardCaptureRs'])) { $result = $response['CustomerCreditCardCaptureRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardCaptureRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardCaptureRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardTxnVoidRs'])) { $result = $response['CustomerCreditCardTxnVoidRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardTxnVoidRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardTxnVoidRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardTxnVoidOrRefundRs'])) { $result = $response['CustomerCreditCardTxnVoidOrRefundRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardTxnVoidOrRefundRs']['@attributes']['statusMessage']; if (isset($response['CustomerCreditCardTxnVoidOrRefundRs']['CreditCardTransID'])) { $identifier = $response['CustomerCreditCardTxnVoidOrRefundRs']['CreditCardTransID']; } } $details->gateway_response = $as_array; if ($result === '0') { //Transaction was successful $details->identifier = $identifier; $details->timestamp = isset($signon['ServerDateTime']) ? $signon['ServerDateTime'] : ''; return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { //Transaction failed $details->reason = $message; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
/** * Makes the actual request to the gateway * * @param string This is the API endpoint currently being used * @param string The data to be passed to the API * @param string A specific content type to define for cURL request * @return object response object */ public static function curl_request($query_string, $payload = NULL, $content_type = NULL, $custom_headers = NULL) { $headers = is_null($custom_headers) ? array() : $custom_headers; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $query_string); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, 0); if (is_null($payload)) { $request = curl_exec($curl); if ($request[0] == '<') { return Payment_Utility::parse_xml($request); } else { return $request; } } else { if (is_null($content_type)) { $xml = TRUE; $headers[] = "Content-Type: text/xml"; } else { if (strpos($content_type, 'xml') !== FALSE) { $xml = TRUE; } $headers[] = "Content-Type: {$content_type}"; } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); $request = curl_exec($curl); if (isset($xml) && $xml === TRUE) { return Payment_Utility::parse_xml($request); } else { return $request; } } }
public function __construct($config) { Payment_Utility::load('file', 'vendor/gocardless/lib/gocardless'); $this->_config = $config; }