public function generateToken() { require "lib/braintree-php-3.5.0/lib/Braintree.php"; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('w7gz99fhtbrhj6y6'); Braintree_Configuration::publicKey('p5hhp9ctz3znhsq3'); Braintree_Configuration::privateKey('2baa5dd4adcb171001ce768fc2edf041'); $clientToken = Braintree_ClientToken::generate(); return $clientToken; }
public function form2() { echo $clientToken = Braintree_ClientToken::generate(); ?> <html> <head> </head> <body> <h1>Braintree Credit Card Transaction Form</h1> <form action="transaction.php" method="POST" id="braintree-payment-form"> <p> <label>Card Number</label> <input type="text" size="20" autocomplete="off" data-encrypted-name="number" /> </p> <p> <label>CVV</label> <input type="text" size="4" autocomplete="off" data-encrypted-name="cvv" /> </p> <p> <label>Expiration (MM/YYYY)</label> <input type="text" size="2" name="month" /> / <input type="text" size="4" name="year" /> </p> <input type="submit" id="submit" /> </form> <script type="text/javascript" src="https://js.braintreegateway.com/v1/braintree.js"></script> <script type="text/javascript"> var braintree = Braintree.create("YourClientSideEncryptionKey"); braintree.onSubmitEncryptForm('braintree-payment-form'); </script> </body> </html> <?php }
public function payment() { $this->request->allowMethod('post'); if (!isset($this->request->data['amount']) || empty($this->request->data['amount'])) { $this->redirect($this->referer()); } $firstName = $lastName = ''; $name = explode(' ', $this->currUser['User']['full_name']); if (count($name) > 0) { $firstName = array_shift($name); $lastName = implode(' ', $name); } $customerData = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $this->currUser['User']['username'], 'phone' => $this->currUser['User']['phone']); try { $customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']); $customer = Braintree_Customer::update('konstruktor-' . $this->currUser['User']['id'], $customerData); } catch (Exception $e) { $customer = Braintree_Customer::create(Hash::merge(array('id' => 'konstruktor-' . $this->currUser['User']['id']), $customerData)); } if ($customer->success) { $customer = $customer->customer; } else { throw new NotFoundException(__d('billing', 'Invalid billing group')); } $this->Session->write('Billing', array('amount' => $this->request->data['amount'])); $this->layout = 'profile_new'; $clientToken = Braintree_ClientToken::generate(); $this->set('clientToken', $clientToken); $this->set('customer', $customer); }
/** * @param array $params * @return \Braintree_Result_Successful|\Braintree_Result_Error|null */ public function generate(array $params = []) { try { return \Braintree_ClientToken::generate($params); } catch (\Exception $e) { return null; } }
public function generateToken($data) { $client_token = Braintree_ClientToken::generate($data); if ($client_token) { return $client_token; } else { return false; } }
function generateClientToken($clientId = "") { if (@isset($clientId) && $clientId !== "") { $clientToken = Braintree_ClientToken::generate(array("customerId" => $clientId)); } else { $clientToken = Braintree_ClientToken::generate(); } return $clientToken; }
/** * Sets up Braintree configuration from config file * @throws \yii\base\InvalidConfigException */ public function init() { foreach (['merchantId', 'publicKey', 'privateKey', 'environment'] as $attribute) { if ($this->{$attribute} === null) { throw new InvalidConfigException(strtr('"{class}::{attribute}" cannot be empty.', ['{class}' => static::className(), '{attribute}' => '$' . $attribute])); } \Braintree_Configuration::$attribute($this->{$attribute}); } $this->clientSideKey = \Braintree_ClientToken::generate(); parent::init(); }
private function _getClientToken() { $environment = Configure::read('Braintree.environment'); $merchantId = Configure::read('Braintree.MerchantId'); $publicKey = Configure::read('Braintree.PublicKey'); $privateKey = Configure::read('Braintree.PrivateKey'); Braintree_Configuration::environment($environment); Braintree_Configuration::merchantId($merchantId); Braintree_Configuration::publicKey($publicKey); Braintree_Configuration::privateKey($privateKey); //Get the Client Token $clientToken = Braintree_ClientToken::generate(); return $clientToken; }
public function getClientToken() { $this->load->library('session'); //$this->config->load('braintree_config'); Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('w2d7snyv86b6m993'); Braintree_Configuration::publicKey('rm724h4nmjw6pg2n'); Braintree_Configuration::privateKey('87b54560036ce7f21ee95c866357341c'); $clientToken = Braintree_ClientToken::generate(); $this->session->set_userdata($clientToken); if (isset($clientToken)) { //$this->session->set_userdata($clientToken); } else { } echo $_SESSION; }
public function get_braintree_token() { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { if (Config::get('app.default_payment') == 'braintree') { Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $clientToken = Braintree_ClientToken::generate(); $response_array = array('success' => true, 'token' => $clientToken); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Please change braintree as default gateway', 'error_code' => 440); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { /* $var = Keywords::where('id', 2)->first(); $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID is not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID is not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function getBraintree() { \Braintree_Configuration::environment('sandbox'); \Braintree_Configuration::merchantId('7hpjkb4p49nb7ntf'); \Braintree_Configuration::publicKey('8k5sw2c7crsmfj97'); \Braintree_Configuration::privateKey('58bd528ee8fe66091d0afc63db67ede4'); //For existing customers // $clientToken = \Braintree_ClientToken::generate(array( // "customerId" => $aCustomerId // )); $clientToken = \Braintree_ClientToken::generate(); //var_dump($clientToken); //$this->setTitle('Braintree'); //$this->setContent( $this->getLayout('braintree', null) ); $this->setTitle('Braintree'); // Set columns directly using a layout $columns = array('one' => $this->getView('payments/braintree', null, dirname(__DIR__))); $this->setContent($this->getLayout('1column', $columns)); }
public static function nonce_for_new_card($options) { $clientTokenOptions = array(); if (array_key_exists("customerId", $options)) { $clientTokenOptions["customerId"] = $options["customerId"]; unset($options["customerId"]); } $clientToken = json_decode(Braintree_ClientToken::generate($clientTokenOptions)); $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint; $options["shared_customer_identifier"] = "fake_identifier_" . rand(); $options["shared_customer_identifier_type"] = "testing"; $response = Braintree_HttpClientApi::post('/client_api/nonces.json', json_encode($options)); if ($response["status"] != 201) { throw new Exception(var_dump($response)); } else { $body = json_decode($response["body"]); return $body->nonce; } }
protected function index() { $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); //Load Braintree Library require_once './vendor/braintree/braintree_php/lib/Braintree.php'; Braintree_Configuration::environment($this->config->get('simple_braintree_payments_mode')); Braintree_Configuration::merchantId($this->config->get('simple_braintree_payments_merchant')); Braintree_Configuration::publicKey($this->config->get('simple_braintree_payments_public_key')); Braintree_Configuration::privateKey($this->config->get('simple_braintree_payments_private_key')); $this->data['clientToken'] = Braintree_ClientToken::generate(); $this->language->load('payment/simple_braintree_payments'); $this->data['text_credit_card'] = $this->language->get('text_credit_card'); $this->data['text_wait'] = $this->language->get('text_wait'); $this->data['entry_cc_owner'] = $this->language->get('entry_cc_owner'); $this->data['entry_cc_number'] = $this->language->get('entry_cc_number'); $this->data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date'); $this->data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2'); $this->data['button_confirm'] = $this->language->get('button_confirm'); $this->data['button_back'] = $this->language->get('button_back'); $this->data['simple_braintree_payments_public_key'] = $this->config->get('simple_braintree_payments_public_key'); $this->data['simple_braintree_payments_cse'] = $this->config->get('simple_braintree_payments_cse'); $this->data['months'] = array(); for ($i = 1; $i <= 12; $i++) { $this->data['months'][] = array('text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)), 'value' => sprintf('%02d', $i)); } $today = getdate(); $this->data['year_expire'] = array(); for ($i = $today['year']; $i < $today['year'] + 11; $i++) { $this->data['year_expire'][] = array('text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)), 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))); } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/simple_braintree_payments.tpl')) { $this->template = $this->config->get('config_template') . '/template/payment/simple_braintree_payments.tpl'; } else { $this->template = 'default/template/payment/simple_braintree_payments.tpl'; } $this->render(); }
public function generateToken($data) { // Braintree_Configuration::environment($this->config->item('braintree_environment')); // Braintree_Configuration::merchantId($this->config->item('braintree_merchant_id')); // Braintree_Configuration::publicKey($this->config->item('braintree_public_key')); // Braintree_Configuration::privateKey($this->config->item('braintree_private_key')); // //this worked fine with just cust id and MID sent in post, but need to be pulling values from session now // Braintree_Configuration::environment($this->input->post('clientToken-environment')); // Braintree_Configuration::merchantId($this->input->post('clientToken-merchantId')); // Braintree_Configuration::publicKey($this->input->post('clientToken-publicKey')); // Braintree_Configuration::privateKey($this->input->post('clientToken-privateKey')); Braintree_Configuration::environment($this->session->userdata('environment')); Braintree_Configuration::merchantId($this->session->userdata('merchantId')); Braintree_Configuration::publicKey($this->session->userdata('publicKey')); Braintree_Configuration::privateKey($this->session->userdata('privateKey')); //echo $data; $client_token = Braintree_ClientToken::generate($data); if ($client_token) { return $client_token; } else { return false; } }
public function __construct($config, $price = 0) { // DO NOT store .ini files in public web root! to bypass figuring that out (if you're hella lazy) // remove $config as a parameter and hardcode your values into this short section $parsed = parse_ini_file($config, TRUE); Braintree_Configuration::environment($parsed['environment']); Braintree_Configuration::merchantId($parsed['merchantId']); Braintree_Configuration::publicKey($parsed['publicKey']); Braintree_Configuration::privateKey($parsed['privateKey']); if ($price > 0) { // angular doesnt like php's $_POST something something // http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data $post_inputs = json_decode(file_get_contents('php://input'), true); $result = Braintree_Transaction::sale(array('amount' => $price, 'paymentMethodNonce' => $post_inputs['nonce'], 'customer' => ['firstName' => $post_inputs['first_name'], 'lastName' => $post_inputs['last_name'], 'email' => $post_inputs['email'], 'company' => $post_inputs['company']], 'creditCard' => ['cardholderName' => $post_inputs['cardholderName'], 'cvv' => $post_inputs['cvv'], 'expirationDate' => $post_inputs['expirationDate']], 'orderId' => $post_inputs['orderId'], 'options' => ['submitForSettlement' => True])); if ($result->success) { $response['success'] = true; $response['message'] = "Success"; $response['id'] = $result->transaction->id; } else { if ($result->transaction) { $response['success'] = false; $response['message'] = "Error processing transaction"; $response['code'] = $result->transaction->processorResponseCode; $response['text'] = $result->transaction->processorResponseText; } else { $response['success'] = false; $response['message'] = "Validation errors"; $response['errors'] = $result->errors->deepAll(); } } $this->response = json_encode($response); } else { // price not provided, create client token $this->client_token = Braintree_ClientToken::generate(); } }
</div> <div id="bar4" class="collapse"> <p> <form id="checkout4" method="post" action="pay.php"> <div id="payment-form4"></div> <input type="submit" value="Pay 10€"> </form> <script src="https://js.braintreegateway.com/v2/braintree.js"></script> <script> // We generated a client token for you so you can test out this code // immediately. In a production-ready integration, you will need to // generate a client token on your server (see section below). var clientToken = "<?php echo Braintree_ClientToken::generate(); ?> "; braintree.setup(clientToken, "dropin", { container: "payment-form4" }); </script> </p> </div> </p> </figcaption> </figure> </li> </div>
public function getBTToken() { $aCustomerId = $_POST["id_user"]; $user = new UserModel(); $user->getByID($aCustomerId); if ($user->device_ids == null || $user->device_ids == "") { if (!$this->createCust($user)) { Generic::errorMsg("error user not created"); die; } } else { $customer = Braintree_Customer::find($aCustomerId); pr($customer); $aCustomerId = $customer->id; // die(); } $clientToken = Braintree_ClientToken::generate(["customerId" => $aCustomerId]); echo "{\"status_code\":1,\"results\":{\"btok\":\"{$clientToken}\"}}"; die; }
public function showBraintree() { try { $customer = Braintree_Customer::find('development_fruit_analytics_user_' . Auth::user()->id); } catch (Braintree_Exception_NotFound $e) { $result = Braintree_Customer::create(array('id' => 'development_fruit_analytics_user_' . Auth::user()->id, 'email' => Auth::user()->email)); if ($result->success) { $customer = $result->customer; } else { // needs error handling } } $clientToken = Braintree_ClientToken::generate(array("customerId" => $customer->id)); return View::make('dev.braintree', array('clientToken' => $clientToken)); }
public function generateClientToken($_customerId = False) { $this->_checkReady(); $options = []; if ($_customerId) { $options['customerId'] = $_customerId; } if ($this->merchantAccountId) { $options['merchantAccountId'] = $this->merchantAccountId; } return Braintree_ClientToken::generate($options); }
public function create_token() { return Braintree_ClientToken::generate(); }
/** * Generates token for further use * * @return string | boolean */ public function getToken() { $customerExists = false; $customerSession = Mage::getSingleton('customer/session'); $magentoCustomerId = false; $magentoCustomerEmail = false; $storeId = null; if ($customerSession->isLoggedIn()) { $magentoCustomerId = $customerSession->getCustomerId(); $magentoCustomerEmail = $customerSession->getCustomer()->getEmail(); } else { if (Mage::app()->getStore()->isAdmin()) { $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); $magentoCustomerId = $quote->getCustomerId(); $magentoCustomerEmail = $quote->getCustomerEmail(); $storeId = $quote->getStoreId(); } } if ($magentoCustomerId && $magentoCustomerEmail) { $customerId = $this->generateCustomerId($magentoCustomerId, $magentoCustomerEmail); try { $customerExists = Braintree_Customer::find($customerId); } catch (Exception $e) { $customerExists = false; } } $params = array("merchantAccountId" => Mage::getStoreConfig('payment/braintree/merchant_account_id', $storeId)); if ($customerExists) { $params['customerId'] = $customerId; } try { $token = Braintree_ClientToken::generate($params); } catch (Exception $e) { Mage::logException($e); return false; } return $this->jsQuoteEscape($token); }
public static function decodedClientToken($params = array()) { $encodedClientToken = Braintree_ClientToken::generate($params); return base64_decode($encodedClientToken); }
<?php include './braintree-php/lib/Braintree.php'; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('mfx4wrcgnhjpqgtw'); Braintree_Configuration::publicKey('s2rdn7zhdvn7fz9b'); Braintree_Configuration::privateKey('75c15e64858c6cc3cb00c18c6dbaaa07'); echo $clientToken = Braintree_ClientToken::generate();
/** * Generate a server side token with the specified account ID * * @return mixed */ public function generateToken() { // Use the class to generate the token return Braintree_ClientToken::generate(array("merchantAccountId" => $this->getMerchantAccountId())); }
function submissionCC($param) { $list_id = $param; $row1 = $this->Common_model->getTableData('paymode', array('id' => '1'))->row(); $amount = get_currency_value_lys(get_currency_code(), 'USD', $this->session->userdata('amount')); if ($amount == 0) { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', translate('Amount must be greater than zero.'))); redirect('rooms/' . $list_id); } $this->session->set_userdata('subtotal', $amount); $data['list_id'] = $list_id; $clientToken = Braintree_ClientToken::generate(array()); $id = $list_id; if ($clientToken == '401') { $username = $this->dx_auth->get_username(); $list_title = $this->Common_model->getTableData('list', array('id' => $id))->row()->title; $email = $this->Common_model->getTableData('users', array('id' => $this->dx_auth->get_user_id()))->row()->email; $admin_email = $this->Common_model->getTableData('users', array('id' => 1))->row()->email; $admin_email_from = $this->dx_auth->get_site_sadmin(); $admin_name = $this->dx_auth->get_site_title(); $email_name = 'payment_issue_to_admin'; $splVars = array("{payment_type}" => 'Braintree', "{site_name}" => $this->dx_auth->get_site_title(), "{username}" => ucfirst($username), "{list_title}" => $list_title, '{email_id}' => $email); $this->Email_model->sendMail($admin_email, $admin_email_from, ucfirst($admin_name), $email_name, $splVars); $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', translate("Braintree business account is misconfigured. Please contact your Administrator."))); redirect('rooms/' . $list_id, "refresh"); } $data['title'] = "Payments"; $data["meta_keyword"] = ""; $data["meta_description"] = ""; $data['clientToken'] = $clientToken; $data['message_element'] = "payments/listpay_checkout"; $this->load->view('template', $data); }
public function get_braintree_token() { $token = Input::get('token'); $owner_id = Input::get('id'); if (Config::get('app.default_payment') == 'braintree') { Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $clientToken = Braintree_ClientToken::generate(); $response_array = array('success' => true, 'token' => $clientToken); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Please change braintree as default gateway', 'error_code' => 440); $response_code = 200; } $response = Response::json($response_array, $response_code); return $response; }
function testErrorsWhenInvalidArgumentIsSupplied() { $this->setExpectedException('InvalidArgumentException', 'invalid keys: customrId'); Braintree_ClientToken::generate(array("customrId" => "1234")); }
public function showPayPlan($planId) { try { $customer = Braintree_Customer::find('fruit_analytics_user_' . Auth::user()->id); } catch (Braintree_Exception_NotFound $e) { $result = Braintree_Customer::create(array('id' => 'fruit_analytics_user_' . Auth::user()->id, 'email' => Auth::user()->email, 'firstName' => Auth::user()->email)); if ($result->success) { $customer = $result->customer; } else { // needs error handling } } // generate clientToken for the user to make payment $clientToken = Braintree_ClientToken::generate(array("customerId" => $customer->id)); // get the detials of the plan $plans = Braintree_Plan::all(); // find the correct plan to show // no way currently to get only one plan foreach ($plans as $plan) { // the plan id needs to be in .env.php (or any other assocc array) for easy access if ($plan->id == 'fruit_analytics_plan_' . $planId) { $planName = $plan->name; } } return View::make('auth.payplan', array('planName' => $planName, 'clientToken' => $clientToken)); }
public function getToken() { $clientToken = Braintree_ClientToken::generate(); //$this->sendSuccess($clientToken); return $clientToken; }
public function pay_provider($id) { $request = Requests::find($id); if (Config::get('app.default_payment') == 'stripe') { $title = ucwords("Transfer amount"); return View::make('transfer_amount')->with('request', $request)->with('title', $title)->with('page', 'walkers'); } else { $this->_braintreeConfigure(); $clientToken = Braintree_ClientToken::generate(); Session::put('error', 'Manual Transfer is not available in braintree.'); $title = ucwords("Transfer amount"); return View::make('transfer_amount')->with('request', $request)->with('clientToken', $clientToken)->with('title', $title)->with('page', 'walks'); } }