/** * 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(); } }
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'); }
public function __construct($config) { Payment_Utility::load('file', 'vendor/gocardless/lib/gocardless'); $this->_config = $config; }