/** * Submit a payment using Advanced Integration Method * * @param array $params assoc array of input parameters for this transaction * * @return array the result in a nice formatted array (or an error object) * @public */ function doDirectPayment(&$params) { $requestArray = $this->formRequestArray($params); $result = Braintree_Transaction::sale($requestArray); if ($result->success) { $params['trxn_id'] = $result->transaction->id; $params['gross_amount'] = $result->transaction->amount; } else { if ($result->transaction) { $errormsg = 'Transactions is not approved'; return self::error($result->transaction->processorResponseCode, $result->message); } else { $error = "Validation errors:<br/>"; foreach ($result->errors->deepAll() as $e) { $error .= $e->message; } return self::error(9001, $error); } } return $params; }
private function _doTestRequest($testPath, $transactionId) { self::_checkEnvironment(); $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . $testPath; $response = $this->_http->put($path); return Braintree_Transaction::factory($response['transaction']); }
/** * @ignore */ protected function _initialize($attributes) { $this->_attributes = $attributes; $addOnArray = array(); if (isset($attributes['addOns'])) { foreach ($attributes['addOns'] as $addOn) { $addOnArray[] = Braintree_AddOn::factory($addOn); } } $this->_attributes['addOns'] = $addOnArray; $discountArray = array(); if (isset($attributes['discounts'])) { foreach ($attributes['discounts'] as $discount) { $discountArray[] = Braintree_Discount::factory($discount); } } $this->_attributes['discounts'] = $discountArray; if (isset($attributes['descriptor'])) { $this->_set('descriptor', new Braintree_Descriptor($attributes['descriptor'])); } $statusHistory = array(); if (isset($attributes['statusHistory'])) { foreach ($attributes['statusHistory'] as $history) { $statusHistory[] = new Braintree_Subscription_StatusDetails($history); } } $this->_attributes['statusHistory'] = $statusHistory; $transactionArray = array(); if (isset($attributes['transactions'])) { foreach ($attributes['transactions'] as $transaction) { $transactionArray[] = Braintree_Transaction::factory($transaction); } } $this->_attributes['transactions'] = $transactionArray; }
public function send() { $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $amount = $this->currency->format($order_info['total'], $order_info['currency_code'], 1.0, false); //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')); // Payment nonce received from the client js side $nonce = $_POST["payment_method_nonce"]; //create object to use as json $json = array(); $result = null; try { // Perform the transaction $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodNonce' => $nonce, 'orderId' => $this->session->data['order_id'])); } catch (Exception $e) { $json['phperror'] = $e->getMessage(); } $json['details'] = $result; if ($result->success) { $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('simple_braintree_payments_order_status_id')); $json['success'] = $this->url->link('checkout/success', '', 'SSL'); } else { $json['error'] = $result->_attributes['message']; } $this->response->setOutput(json_encode($json)); }
function braintree($data) { foreach ($data as $k => $v) { ${$k} = $v; } try { include_once 'config.braintree.php'; $customer = Braintree_Customer::create(['firstName' => $first_name, 'lastName' => $last_name]); if (!isset($nonce) || empty($nonce)) { throw new Exception("An unknown error has occurred"); } if ($customer->success) { $transaction = Braintree_Transaction::sale(['amount' => $price, 'customerId' => $customer->customer->id, 'paymentMethodNonce' => $nonce]); if ($transaction->success) { $this->save($data, __FUNCTION__, $transaction->transaction, 1); return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $transaction->transaction->status)]); } else { throw new Exception($transaction->message); } } } catch (Exception $e) { $this->save($data, __FUNCTION__, (string) $e, 0); return json_encode(["status" => false, "msg" => $e->getMessage()]); } }
public function directpay($var = array()) { $payment = array("amount" => $var['postVal']['amount'], "creditCard" => array("number" => $var['postVal']['ccNum'], "cvv" => $var['postVal']['ccCCV'], "cardholderName" => $var['postVal']['ccHolder'], "expirationMonth" => $var['postVal']['ccExpMM'], "expirationYear" => $var['postVal']['ccExpYY']), "merchantAccountId" => $var['postVal']['cur'], "options" => array("submitForSettlement" => true)); $sale = Braintree_Transaction::sale($payment); $result = array(); if ($sale->success) { $result['status'] = "200"; $result['detail']['id'] = $sale->transaction->id; $result['detail']['sales_id'] = $sale->transaction->id; $result['detail']['state'] = $sale->transaction->status; $result['detail']['create_time'] = $sale->transaction->createdAt->format("Y-m-d H:i:s"); $result['detail']['update_time'] = $sale->transaction->updatedAt->format("Y-m-d H:i:s"); $result['detail']['currency'] = $sale->transaction->currencyIsoCode; $result['detail']['amount'] = $sale->transaction->amount; $result['detail']['gateway'] = "Braintree"; } else { if ($sale->transaction) { $result['status'] = $sale->transaction->processorResponseCode; $result['errMsg'] = $sale->message; } else { $result['status'] = "400"; $errMsg = ""; foreach ($sale->errors->deepAll() as $error) { $errMsg .= "- " . $error->message . "<br/>"; } $result['errMsg'] = $errMsg; } } return $result; }
protected function _initialize($attributes) { $this->_attributes = $attributes; if (isset($attributes['subject']['apiErrorResponse'])) { $wrapperNode = $attributes['subject']['apiErrorResponse']; } else { $wrapperNode = $attributes['subject']; } if (isset($wrapperNode['subscription'])) { $this->_set('subscription', Braintree_Subscription::factory($attributes['subject']['subscription'])); } if (isset($wrapperNode['merchantAccount'])) { $this->_set('merchantAccount', Braintree_MerchantAccount::factory($wrapperNode['merchantAccount'])); } if (isset($wrapperNode['transaction'])) { $this->_set('transaction', Braintree_Transaction::factory($wrapperNode['transaction'])); } if (isset($wrapperNode['disbursement'])) { $this->_set('disbursement', Braintree_Disbursement::factory($wrapperNode['disbursement'])); } if (isset($wrapperNode['partnerMerchant'])) { $this->_set('partnerMerchant', Braintree_PartnerMerchant::factory($wrapperNode['partnerMerchant'])); } if (isset($wrapperNode['errors'])) { $this->_set('errors', new Braintree_Error_ValidationErrorCollection($wrapperNode['errors'])); $this->_set('message', $wrapperNode['message']); } }
/** * overrides default constructor * @ignore * @param array $response gateway response array */ public function __construct($response) { $this->_attributes = $response; $this->_set('errors', new Braintree_Error_ErrorCollection($response['errors'])); if (isset($response['verification'])) { $this->_set('creditCardVerification', new Braintree_Result_CreditCardVerification($response['verification'])); } else { $this->_set('creditCardVerification', null); } if (isset($response['transaction'])) { $this->_set('transaction', Braintree_Transaction::factory($response['transaction'])); } else { $this->_set('transaction', null); } if (isset($response['subscription'])) { $this->_set('subscription', Braintree_Subscription::factory($response['subscription'])); } else { $this->_set('subscription', null); } if (isset($response['merchantAccount'])) { $this->_set('merchantAccount', Braintree_MerchantAccount::factory($response['merchantAccount'])); } else { $this->_set('merchantAccount', null); } }
/** * create signatures for different call types * @ignore */ public static function init() { self::$_createCustomerSignature = array(self::$_transparentRedirectKeys, array('customer' => Braintree_Customer::createSignature())); self::$_updateCustomerSignature = array(self::$_transparentRedirectKeys, 'customerId', array('customer' => Braintree_Customer::updateSignature())); self::$_transactionSignature = array(self::$_transparentRedirectKeys, array('transaction' => Braintree_Transaction::createSignature())); self::$_createCreditCardSignature = array(self::$_transparentRedirectKeys, array('creditCard' => Braintree_CreditCard::createSignature())); self::$_updateCreditCardSignature = array(self::$_transparentRedirectKeys, 'paymentMethodToken', array('creditCard' => Braintree_CreditCard::updateSignature())); }
function donate($nonce, $info) { $result = Braintree_Transaction::sale(['amount' => $info['amount'], 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => True]]); if (!isset($result->transaction) || !$result->transaction) { return $this->processErrors('donation', $result->errors->deepAll()); } return $this->retrieveTransactioResults($result->success, $result->transaction, $info); }
function braintreepay(){ $nonce = $_POST["payment_method_nonce"]; $amount = $_POST["amount"]; $result = Braintree_Transaction::sale([ 'amount'=>''.$amount, 'paymentMethodNonce' => 'fake-valid-nonce' ]); echo $result->success; }
public function searchTransactions() { $transactions = Braintree_Transaction::search($data); if ($transactions) { return $transactions; } else { return false; } }
private function _sale($postFormData, $nonce) { $amount = $postFormData['Order']['amount']; $currencyModelObj = ClassRegistry::init('Currency'); $currency = $currencyModelObj->getCurrencyByAbbreviation($postFormData['Order']['currency_abbr']); $convertedAmount = (double) round($amount / $currency['Currency']['rate'], 2); $sale = Braintree_Transaction::sale(['amount' => $convertedAmount, 'paymentMethodNonce' => $nonce]); return $sale; }
public function pay($data) { global $_SESSION; $this->debug($_SESSION); $billingAddress = $this->getAddress($data['billingAddress'], true)[0]; $shippingAddress = $this->getAddress($data['shippingAddress'], true)[0]; $sale = Braintree_Transaction::sale(['amount' => '10.00', 'paymentMethodNonce' => $data['payment_method_nonce'], 'shipping' => ['firstName' => $shippingAddress['address_first_name'], 'lastName' => $shippingAddress['address_last_name'], 'company' => $shippingAddress['address_company_name'], 'streetAddress' => $shippingAddress['address_street'], 'extendedAddress' => $shippingAddress['address_apartment'], 'locality' => $shippingAddress['address_city'], 'region' => $shippingAddress['address_county'], 'postalCode' => $shippingAddress['address_postcode'], 'countryCodeAlpha2' => $shippingAddress['address_country']], 'billing' => ['firstName' => $billingAddress['address_first_name'], 'lastName' => $billingAddress['address_last_name'], 'company' => $billingAddress['address_company_name'], 'streetAddress' => $billingAddress['address_street'], 'extendedAddress' => $billingAddress['address_apartment'], 'locality' => $billingAddress['address_city'], 'region' => $billingAddress['address_county'], 'postalCode' => $billingAddress['address_postcode'], 'countryCodeAlpha2' => $billingAddress['address_country']], 'options' => ['submitForSettlement' => true]]); return $sale; }
function testGenerate_canBeGroupedByACustomField() { $transaction = Braintree_Transaction::saleNoValidate(array('amount' => '100.00', 'creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12'), 'customFields' => array('store_me' => 'custom value'), 'options' => array('submitForSettlement' => true))); Braintree_TestHelper::settle($transaction->id); $today = new Datetime(); $result = Braintree_SettlementBatchSummary::generate(Braintree_TestHelper::nowInEastern(), 'store_me'); $this->assertTrue($result->success); $this->assertTrue(count($result->settlementBatchSummary->records) > 0); $this->assertArrayHasKey('store_me', $result->settlementBatchSummary->records[0]); }
function test__isset() { $transaction = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100', 'cardType' => 'MasterCard'))); $this->assertEquals('MasterCard', $transaction->creditCardDetails->cardType); $this->assertFalse(empty($transaction->creditCardDetails->cardType)); $this->assertTrue(isset($transaction->creditCardDetails->cardType)); $transaction = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'))); $this->assertTrue(empty($transaction->creditCardDetails->cardType)); $this->assertFalse(isset($transaction->creditCardDetails->cardType)); }
function quick_transaction($cust_id, $token, $amount) { $result = Braintree_Transaction::sale(array('amount' => $amount, 'customerId' => $cust_id, 'paymentMethodToken' => $token)); if ($result->success) { $this->_log_transaction($result->transaction); return true; } // func still running means errors! $this->_parse_errors($result); return false; }
/** * Transaction Settlement * * @param $trans_id * @return object */ public function transSettlement($trans_id) { $transaction = Braintree_Transaction::find($trans_id); if ($transaction->status == Braintree_Transaction::SETTLED) { $result = array('status' => $transaction->status, 'is_settlement' => true); return $result; } else { $result = array('status' => $transaction->status, 'is_settlement' => false); return $result; } }
/** * Refund transaction * * @param $transaction_id * @param null $amount * @param bool $void * @return object */ public function refund($transaction_id, $amount = NULL, $void = TRUE) { //try void if ($void == TRUE) { $result = Braintree_Transaction::void($transaction_id); if ($result->success == TRUE) { return $result; } } //if already settled, do refund $result = Braintree_Transaction::refund($transaction_id, $amount); return $result; }
/** * Prepare the collection for the report * * @return $this|Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { // Add in a new collection $collection = new Varien_Data_Collection(); // Init the wrapper $wrapper = Mage::getModel('gene_braintree/wrapper_braintree'); // Validate the credentials if ($wrapper->validateCredentials()) { // Grab all transactions $transactions = Braintree_Transaction::search($this->_prepareBraintreeSearchQuery()); // Retrieve the order IDs $orderIds = array(); /* @var $transaction Braintree_Transaction */ foreach ($transactions as $transaction) { $orderIds[] = $transaction->orderId; } // Retrieve all of the orders from a collection $orders = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('increment_id', array('in' => $orderIds)); /* @var $transaction Braintree_Transaction */ foreach ($transactions as $transaction) { // Create a new varien object $transactionItem = new Varien_Object(); $transactionItem->setData((array) $transaction->_attributes); // Grab the Magento order from the previously built collection /* @var $magentoOrder Mage_Sales_Model_Order */ $magentoOrder = $orders->getItemByColumnValue('increment_id', $transaction->orderId); // Set the Magento Order ID into the collection // Not all transactions maybe coming from Magento if ($magentoOrder && $magentoOrder->getId()) { $transactionItem->setMagentoOrderId($magentoOrder->getId()); $transactionItem->setOrderStatus($magentoOrder->getStatus()); } else { $transactionItem->setOrderStatus('<em>Unknown</em>'); } // Add the item into the collection $collection->addItem($transactionItem); } } else { // If the Braintree details aren't valid take them to the configuration page Mage::getSingleton('adminhtml/session')->addError(Mage::helper('gene_braintree')->__('You must enter valid details into the Braintree v.zero - Configuration payment method before viewing transactions.')); // Send the users on their way Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('/system_config/edit/section/payment') . '#payment_gene_braintree-head'); Mage::app()->getResponse()->sendResponse(); // Stop processing this method return false; } $this->setCollection($collection); parent::_prepareCollection(); return $this; }
function charge(&$order) { //create a code for the order if (empty($order->code)) { $order->code = $order->getRandomCode(); } //what amount to charge? $amount = $order->InitialPayment; //tax $order->subtotal = $amount; $tax = $order->getTax(true); $amount = round((double) $order->subtotal + (double) $tax, 2); //create a customer $this->getCustomer($order); if (empty($this->customer)) { //failed to create customer return false; } //charge try { $response = Braintree_Transaction::sale(array('amount' => $amount, 'customerId' => $this->customer->id)); } catch (Exception $e) { //$order->status = "error"; $order->errorcode = true; $order->error = "Error: " . $e->getMessage(); $order->shorterror = $order->error; return false; } if ($response->success) { //successful charge $transaction_id = $response->transaction->id; $response = Braintree_Transaction::submitForSettlement($transaction_id); if ($response->success) { $order->payment_transaction_id = $transaction_id; $order->updateStatus("success"); return true; } else { $order->errorcode = true; $order->error = __("Error during settlement:", "pmpro") . " " . $response->message; $order->shorterror = $response->message; return false; } } else { //$order->status = "error"; $order->errorcode = true; $order->error = __("Error during charge:", "pmpro") . " " . $response->message; $order->shorterror = $response->message; return false; } }
/** * Transaction settlement method * for cronjob * @param $trans_id * @return object */ public function transactionSettlement($trans_id) { $transaction = Braintree_Transaction::find($trans_id); //return $transaction; if ($transaction->status == Braintree_Transaction::SETTLED) { $result = array('is_settlement' => true); } else { $result = array('is_settlement' => false); } $result['recurring'] = $transaction->recurring; $result['status'] = $transaction->status; $result['package_id'] = $transaction->planId; $result['subscription_id'] = $transaction->subscriptionId; return $result; }
/** * Braintree sale function * @return array array(status=>boolean,result=>array(),message=>string) */ public function singleCharge($submitForSettlement = true, $storeInVaultOnSuccess = true) { $this->options['options']['submitForSettlement'] = $submitForSettlement; $this->options['options']['storeInVaultOnSuccess'] = $storeInVaultOnSuccess; $result = Braintree_Transaction::sale($this->options); if ($result->success) { return array('status' => true, 'result' => $result); } else { if ($result->transaction) { return array('status' => false, 'result' => $result); } else { return array('status' => false, 'result' => $result); } } }
/** * After form has been submitted, send CC details to Braintree and ensure the card is going to work * If not, void the validation result (processed elsewhere) and have the submit the form again * * @param $feed - Current configured payment feed * @param $submission_data - Contains form field data submitted by the user as well as payment information (i.e. payment amount, setup fee, line items, etc...) * @param $form - Current form array containing all form settings * @param $entry - Current entry array containing entry information (i.e data submitted by users). NOTE: the entry hasn't been saved to the database at this point, so this $entry object does not have the "ID" property and is only a memory representation of the entry. * @return array - Return an $authorization array in the following format: * [ * "is_authorized" => true|false, * "error_message" => "Error message", * "transaction_id" => "XXX", * * //If the payment is captured in this method, return a "captured_payment" array with the following information about the payment * "captured_payment" => ["is_success"=>true|false, "error_message" => "error message", "transaction_id" => "xxx", "amount" => 20] * ] * @since 1.0 * @return void */ protected function authorize($feed, $submission_data, $form, $entry) { // Prepare authorization response payload $authorization = array('is_authorized' => false, 'error_message' => apply_filters('gform_braintree_credit_card_failure_message', __('Your card could not be billed. Please ensure the details you entered are correct and try again.', 'gravity-forms-braintree')), 'transaction_id' => '', 'captured_payment' => array('is_success' => false, 'error_message' => '', 'transaction_id' => '', 'amount' => $submission_data['payment_amount'])); // Perform capture in this function. For this version, we won't authorize and then capture later // at least, not in this version if ($settings = $this->get_plugin_settings()) { // Sanitize card number, removing dashes and spaces $card_number = str_replace(array('-', ' '), '', $submission_data['card_number']); // Prepare Braintree payload $args = array('amount' => $submission_data['payment_amount'], 'creditCard' => array('number' => $card_number, 'expirationDate' => sprintf('%s/%s', $submission_data['card_expiration_date'][0], $submission_data['card_expiration_date'][1]), 'cardholderName' => $submission_data['card_name'], 'cvv' => $submission_data['card_security_code'])); try { // Configure Braintree environment Braintree_Configuration::environment(strtolower($settings['environment'])); Braintree_Configuration::merchantId($settings['merchant-id']); Braintree_Configuration::publicKey($settings['public-key']); Braintree_Configuration::privateKey($settings['private-key']); // Set to auto settlemt if applicable if ($settings['settlement'] == 'Yes') { $args['options']['submitForSettlement'] = 'true'; } // Send transaction to Braintree $result = Braintree_Transaction::sale($args); // Update response to reflect successful payment if ($result->success == '1') { $authorization['is_authorized'] = true; $authorization['error_message'] = ''; $authorization['transaction_id'] = $result->transaction->_attributes['id']; $authorization['captured_payment'] = array('is_success' => true, 'transaction_id' => $result->transaction->_attributes['id'], 'amount' => $result->transaction->_attributes['amount'], 'error_message' => '', 'payment_method' => 'Credit Card'); } else { // Append gateway response text to error message if it exists. If it doesn't exist, a more hardcore // failure has occured and it won't do the user any good to see it other than a general error message if (isset($result->_attributes['transaction']->_attributes['processorResponseText'])) { $authorization['error_message'] .= sprintf('. Your bank said: %s.', $result->_attributes['transaction']->_attributes['processorResponseText']); } } } catch (Exception $e) { // Do nothing with exception object, just fallback to generic failure } return $authorization; } 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(); } }
function testIsset() { $t = Braintree_Transaction::factory(array('creditCard' => array('expirationMonth' => '05', 'expirationYear' => '2010', 'bin' => '510510', 'last4' => '5100'), 'customer' => array(), 'billing' => array(), 'descriptor' => array(), 'shipping' => array(), 'subscription' => array('billingPeriodStartDate' => '1983-07-12'), 'statusHistory' => array())); $this->assertTrue(isset($t->creditCard)); $this->assertFalse(empty($t->creditCard)); }
/** * Clone a transaction * * @param $transactionId * @param $amount * * @return bool|mixed */ public function cloneTransaction($transactionId, $amount, $submitForSettlement = true) { // Attempt to clone the transaction try { $result = Braintree_Transaction::cloneTransaction($transactionId, array('amount' => $amount, 'options' => array('submitForSettlement' => $submitForSettlement))); return $result; } catch (Exception $e) { // Log the issue Gene_Braintree_Model_Debug::log(array('cloneTransaction' => $e)); return false; } }
function _send_payment_request_callback() { Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('4r57w2h7hgyqk52g'); Braintree_Configuration::publicKey('4y98n9vt93pvqpgj'); Braintree_Configuration::privateKey('32d966b730def400269d835b030fd109'); /*$amount = 10.30; $card = '4111111111111111'; $padDateMonth = '10'; $expDateYear = '20'; $cvv = '911'; */ $card_detail = explode('/', $_POST['expire_card']); $amount = $_POST['amount']; $card = $_POST['credit_card']; $padDateMonth = $card_detail[0]; $expDateYear = $card_detail[1]; $cvv = $_POST['cvv']; $result = Braintree_Transaction::sale(array('amount' => round(floatval($amount)), 'creditCard' => array('number' => $card, 'expirationMonth' => $padDateMonth, 'expirationYear' => $expDateYear, 'cvv' => $cvv))); if ($result->success == 1) { $trans_id = $result->transaction->_attributes['id']; $donatorData = array('trans_id' => $trans_id, 'team_id' => $_POST['team_id'], 'payment_type' => 'Online', 'amount' => $amount, 'donator_name' => $_POST['donator_name'], 'donator_email' => $_POST['donator_email'], 'trans_detail' => serialize($result->transaction->_attributes)); $objDonator = new tblDonator(); $objDonator->insert($donatorData); echo 1; } else { echo 0; } die; }
<?php include_once 'braintree-init.php'; $nonce = $_POST['payment_method_nonce']; $total = $_POST['total']; print_r($_POST); echo $nonce; $result = Braintree_Transaction::sale(['amount' => $total, 'paymentMethodNonce' => $nonce]); echo $result;
public function braintree_success() { $result = Braintree_Transaction::sale(array('amount' => get_currency_value_lys(get_currency_code(), 'USD', $this->session->userdata('list_commission')), "paymentMethodNonce" => $_POST['payment_method_nonce'], 'options' => array('submitForSettlement' => true))); $transaction = $result->transaction; /* if($result->success == 1) { if($result->message == "Amount must be greater than zero.") { $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error',$result->message)); redirect('rooms/'.$this->input->post('custom',true), "refresh"); } */ if (!$this->dx_auth->is_logged_in() || !$this->facebook_lib->logged_in()) { //$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error',translate('Session expired, please try again.'))); //redirect('users/signin'); } if ($transaction->status == "authorized" || $transaction->status == "submitted_for_settlement") { $listId = $this->input->post('custom', true); $condition = array('id' => $listId); $data['status'] = 1; $data['list_pay'] = 1; $data['is_enable'] = 1; $data['payment'] = 1; $this->Common_model->updateTableData('list', NULL, $condition, $data); if (!$this->dx_auth->is_logged_in() || !$this->facebook_lib->logged_in()) { //$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error',translate('Session expired, please try again.'))); //redirect('users/signin'); } $query_user = $this->Common_model->getTableData('users', array('id' => $this->dx_auth->get_user_id()))->row(); $username = $query_user->username; $insertData = array('list_id' => $listId, 'conversation_id' => $listId, 'userby' => $this->dx_auth->get_user_id(), 'userto' => 1, 'message' => "{$username} created a new list.", 'created' => time(), 'message_type ' => 10); $this->Message_model->sentMessage($insertData); $host_email = $query_user->email; $admin_email = $this->dx_auth->get_site_sadmin(); $admin_name = $this->dx_auth->get_site_title(); $admin_to_email = $this->Common_model->getTableData('users', array('id' => 1))->row()->email; $query_list = $this->Common_model->getTableData('list', array('id' => $listId))->row(); $currency = $query_list->currency; $price = $query_list->price; $title = $query_list->title; $link = base_url() . 'rooms/' . $listId; $email_name = 'list_create_host'; $splVars = array("{host_name}" => $username, "{price}" => $currency . $price, "{link}" => $link, "{list_title}" => $title, "{site_name}" => $this->dx_auth->get_site_title()); $this->Email_model->sendMail($host_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); $email_name = 'list_create_admin'; $splVars = array("{host_name}" => $username, "{price}" => $currency . $price, "{link}" => $link, "{list_title}" => $title, "{site_name}" => $this->dx_auth->get_site_title()); $this->Email_model->sendMail($admin_to_email, $admin_email, ucfirst($admin_name), $email_name, $splVars); $data_listpay['list_id'] = $listId; $data_listpay['amount'] = $this->session->userdata('list_commission'); $data_listpay['currency'] = get_currency_code(); $data_listpay['created'] = time(); $this->db->insert('list_pay', $data_listpay); $data['title'] = "Payment Success !"; $data['message_element'] = "payments/paypal_success"; $this->load->view('template', $data); //redirect('rooms/edit/'.$listId, 'refresh'); //$this->session->set_flashdata('flash_message', $this->Common_model->flash_message('success',translate('Rooms added successfully.'))); //redirect('rooms/'.$listId, 'refresh'); } else { $data['title'] = "Payment Cancelled !"; $data['message_element'] = "payments/paypal_cancel"; $this->load->view('template', $data); } /* } else { $data['title']="Payment Cancelled !"; $data['message_element'] = "payments/paypal_cancel"; $this->load->view('template',$data); } */ }