function testCreate_throwsIfInvalidKey() { $this->setExpectedException('InvalidArgumentException', 'invalid keys: invalidKey'); Braintree_PaymentMethod::create(array('invalidKey' => 'foo')); }
/** * Build up the sale request * * @param $amount * @param array $paymentDataArray * @param Mage_Sales_Model_Order $order * @param bool $submitForSettlement * @param bool $deviceData * @param bool $storeInVault * @param bool $threeDSecure * @param array $extra * * @return array * * @throws Mage_Core_Exception */ public function buildSale($amount, array $paymentDataArray, Mage_Sales_Model_Order $order, $submitForSettlement = true, $deviceData = false, $storeInVault = false, $threeDSecure = false, $extra = array()) { // Check we always have an ID if (!$order->getIncrementId()) { Mage::throwException('Your order has become invalid, please try refreshing.'); } // Store whether or not we created a new method $createdMethod = false; // Are we storing in the vault, from a guest customer account? if ($storeInVault && Mage::getSingleton('checkout/session')->getGuestBraintreeCustomerId() && ($token = Mage::getSingleton('checkout/session')->getGuestPaymentToken())) { if ($this->checkPaymentMethod($token)) { // Remove this from the session so it doesn't get deleted at the end of checkout Mage::getSingleton('checkout/session')->unsGuestBraintreeCustomerId(); Mage::getSingleton('checkout/session')->unsGuestPaymentToken(); // We no longer need this nonce unset($paymentDataArray['paymentMethodNonce']); // Instead use the token $paymentDataArray['paymentMethodToken'] = $token; // Create a flag for other methods $createdMethod = true; } else { // If the method doesn't exist, clear the token and re-build the sale Mage::getSingleton('checkout/session')->unsGuestPaymentToken(); return $this->buildSale($amount, $paymentDataArray, $order, $submitForSettlement, $deviceData, $storeInVault, $threeDSecure, $extra); } } else { if ($storeInVault && $this->checkIsCustomer() && isset($paymentDataArray['paymentMethodNonce'])) { // If the user is already a customer and wants to store in the vault we've gotta do something a bit special // Do we already have a saved token in the session? if ($token = Mage::getSingleton('checkout/session')->getTemporaryPaymentToken()) { if ($this->checkPaymentMethod($token)) { // Remove this from the session so it doesn't get deleted at the end of checkout Mage::getSingleton('checkout/session')->unsTemporaryPaymentToken(); // We no longer need this nonce unset($paymentDataArray['paymentMethodNonce']); // Instead use the token $paymentDataArray['paymentMethodToken'] = $token; // Create a flag for other methods $createdMethod = true; } else { // If the method doesn't exist, clear the token and re-build the sale Mage::getSingleton('checkout/session')->unsTemporaryPaymentToken(); return $this->buildSale($amount, $paymentDataArray, $order, $submitForSettlement, $deviceData, $storeInVault, $threeDSecure, $extra); } } else { // Create the payment method with this data $paymentMethodCreate = array('customerId' => $this->getBraintreeId(), 'paymentMethodNonce' => $paymentDataArray['paymentMethodNonce'], 'billingAddress' => $this->buildAddress($order->getBillingAddress())); // Log the create array Gene_Braintree_Model_Debug::log(array('Braintree_PaymentMethod' => $paymentMethodCreate)); // Create a new billing method $result = Braintree_PaymentMethod::create($paymentMethodCreate); // Log the response from Braintree Gene_Braintree_Model_Debug::log(array('Braintree_PaymentMethod:result' => $result)); // Verify the storing of the card was a success if (isset($result->success) && $result->success == true) { /* @var $paymentMethod Braintree_CreditCard */ $paymentMethod = $result->paymentMethod; // Check to see if the token is set if (isset($paymentMethod->token) && !empty($paymentMethod->token)) { // We no longer need this nonce unset($paymentDataArray['paymentMethodNonce']); // Instead use the token $paymentDataArray['paymentMethodToken'] = $paymentMethod->token; // Create a flag for other methods $createdMethod = true; } } else { Mage::throwException($result->message . Mage::helper('gene_braintree')->__(' Please try again or attempt refreshing the page.')); } } } } // Build up the initial request parameters $request = array('amount' => $amount, 'orderId' => $order->getIncrementId(), 'merchantAccountId' => $this->getMerchantAccountId($order), 'channel' => 'MagentoVZero', 'options' => array('submitForSettlement' => $submitForSettlement, 'storeInVault' => $storeInVault)); // Input the allowed payment method info $allowedPaymentInfo = array('paymentMethodNonce', 'paymentMethodToken', 'token', 'cvv'); foreach ($paymentDataArray as $key => $value) { if (in_array($key, $allowedPaymentInfo)) { if ($key == 'cvv') { $request['creditCard']['cvv'] = $value; } else { $request[$key] = $value; } } else { Mage::throwException($key . ' is not allowed within $paymentDataArray'); } } // Include the customer if we're creating a new one if (!$this->checkIsCustomer() && (Mage::getSingleton('customer/session')->isLoggedIn() || (Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == 'login_in' || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER))) { $request['customer'] = $this->buildCustomer($order); } else { // If the customer exists but we aren't using the vault we want to pass a customer object with no ID $request['customer'] = $this->buildCustomer($order, false); } // Do we have any deviceData to send over? if ($deviceData) { $request['deviceData'] = $deviceData; } // Include the shipping address if ($order->getShippingAddress()) { $request['shipping'] = $this->buildAddress($order->getShippingAddress()); } // Include the billing address if ($order->getBillingAddress()) { $request['billing'] = $this->buildAddress($order->getBillingAddress()); } // Is 3D secure enabled? if ($threeDSecure !== false && !$createdMethod) { $request['options']['three_d_secure']['required'] = true; } // Any extra information we want to supply if (!empty($extra) && is_array($extra)) { $request = array_merge($request, $extra); } return $request; }
function testCreate_fromPayPalACcount() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $plan = Braintree_SubscriptionTestHelper::triallessPlan(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $subscriptionResult = Braintree_Subscription::create(array('paymentMethodToken' => $paymentMethodToken, 'planId' => $plan['id'])); $this->assertTrue($subscriptionResult->success); $transaction = $subscriptionResult->subscription->transactions[0]; $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail); }
function testDelete_worksWithPayPalAccounts() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalAccountResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $this->assertTrue($paypalAccountResult->success); Braintree_PaymentMethod::delete($paymentMethodToken); $this->setExpectedException('Braintree_Exception_NotFound'); Braintree_PaymentMethod::find($paymentMethodToken); }
/** * Saves Credit Card and customer (if new) in vault * * @throws Mage_Core_Exception * @return boolean */ public function saveInVault($postData, $token = false) { $post = $this->_protectArray($postData); $customerId = Mage::getSingleton('customer/session')->getCustomerId(); if (!$customerId) { Mage::throwException(Mage::helper('braintree_payments')->__('Invalid Customer ID provided')); } $customerId = Mage::helper('braintree_payments')->generateCustomerId($customerId, Mage::getSingleton('customer/session')->getCustomer()->getEmail()); $nonce = isset($post['nonce']) ? $post['nonce'] : ''; if (!$this->_validateCustomerAddressData($post)) { Mage::throwException(Mage::helper('braintree_payments')->__('Invalid Address Data provided')); } $request = array('billingAddress' => array('firstName' => $post['credit_card']['billing_address']['first_name'], 'lastName' => $post['credit_card']['billing_address']['last_name'], 'streetAddress' => $post['credit_card']['billing_address']['street_address'], 'locality' => $post['credit_card']['billing_address']['locality'], 'postalCode' => $post['credit_card']['billing_address']['postal_code'], 'countryCodeAlpha2' => $post['credit_card']['billing_address']['country_code_alpha2'])); if (isset($post['credit_card']['billing_address']['extended_address']) && $post['credit_card']['billing_address']['extended_address']) { $request['billingAddress']['extendedAddress'] = $post['credit_card']['billing_address']['extended_address']; } if (isset($post['credit_card']['billing_address']['region']) && $post['credit_card']['billing_address']['region']) { $request['billingAddress']['region'] = $post['credit_card']['billing_address']['region']; } if (isset($post['credit_card']['billing_address']['company']) && $post['credit_card']['billing_address']['company']) { $request['billingAddress']['company'] = $post['credit_card']['billing_address']['company']; } if ($token) { // update card $request['billingAddress']['options'] = array('updateExisting' => true); $extendedRequest = array('creditCard' => array('paymentMethodNonce' => $nonce, 'billingAddress' => $request['billingAddress'], 'options' => array('updateExistingToken' => $token))); if (isset($post['credit_card']['options']['make_default']) && $post['credit_card']['options']['make_default']) { $extendedRequest['creditCard']['options']['makeDefault'] = true; } $this->_debug($token); $this->_debug($extendedRequest); $result = Braintree_Customer::update($customerId, $extendedRequest); $this->_debug($result); } else { if (!$this->_allowDuplicateCards()) { $request['options'] = array('failOnDuplicatePaymentMethod' => true); } if ($this->exists($customerId)) { // add new card for existing customer $request['customerId'] = $customerId; $request['paymentMethodNonce'] = $nonce; $this->_debug($request); $result = Braintree_PaymentMethod::create($request); $this->_debug($result); } else { // add new card and new customer $extendedRequest = array('id' => $customerId, 'firstName' => $post['credit_card']['billing_address']['first_name'], 'lastName' => $post['credit_card']['billing_address']['last_name'], 'email' => Mage::getSingleton('customer/session')->getCustomer()->getEmail(), 'paymentMethodNonce' => $nonce, 'creditCard' => $request); if (isset($post['credit_card']['billing_address']['company']) && $post['credit_card']['billing_address']['company']) { $extendedRequest['company'] = $post['credit_card']['billing_address']['company']; } $this->_debug($extendedRequest); $result = Braintree_Customer::create($extendedRequest); $this->_debug($result); } } if (!$result->success) { Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result)); } return true; }
function testCreate_withVaultedPayPal() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $result = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodToken' => $paymentMethodToken)); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail); $this->assertNotNull($transaction->paypalDetails->imageUrl); $this->assertNotNull($transaction->paypalDetails->debugId); }
$postData = explode("&", urldecode($_POST['data'])); //[SETTING UP POST DATA TO SUPPORT AJAX] foreach ($postData as $key => $value) { $postValue = explode("=", $value); $_POST[$postValue[0]] = $postValue[1]; } unset($_POST['data']); } if ($_POST['verify'] == "true") { echo "With Verify </br>"; $para_Arr = array('customerId' => $_POST['customer_id'], 'paymentMethodNonce' => $_POST["payment_method_nonce"], 'options' => array('verifyCard' => true)); } else { echo "Without Verify </br>"; $para_Arr = array('customerId' => $_POST['customer_id'], 'paymentMethodNonce' => $_POST["payment_method_nonce"]); } $result = Braintree_PaymentMethod::create($para_Arr); $file = './data/token.txt'; //[ADD Customer ID to text file] $token = $result->paymentMethod->token . "\r\n"; // Write the contents to the file, // using the FILE_APPEND flag to append the content to the end of the file // and the LOCK_EX flag to prevent anyone else writing to the file at the same time file_put_contents($file, $token, FILE_APPEND | LOCK_EX); //print_r($result); echo "<div style='height:300px; overflow-y:scroll; background-color:#fff;'> <h3>API response</h3>"; echo json_encode($result, JSON_PRETTY_PRINT); echo "</div>"; } elseif ($_REQUEST['_act'] == 'payByToken') { if (isset($_POST['data'])) { $postData = explode("&", urldecode($_POST['data'])); //[SETTING UP POST DATA TO SUPPORT AJAX]
function testDelete() { $paymentMethodToken = 'PAYPALToken-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $http = new Braintree_HttpClientApi(Braintree_Configuration::$global); $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); Braintree_PayPalAccount::delete($paymentMethodToken); $this->setExpectedException('Braintree_Exception_NotFound'); Braintree_PayPalAccount::find($paymentMethodToken); }
/** * @param array $attribs * @return \Braintree_Result_Successful|\Braintree_Result_Error */ public function create(array $attribs) { return \Braintree_PaymentMethod::create($attribs); }
public function checkout() { $this->layout = 'profile_new'; if (!$this->request->is('post')) { throw new NotFoundException(__d('billing', 'Incorrect request type')); } $customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']); if (isset($this->request->data['payment_method_nonce'])) { $nonceFromTheClient = $this->request->data['payment_method_nonce']; $payment = Braintree_PaymentMethod::create(['customerId' => 'konstruktor-' . $this->currUser['User']['id'], 'paymentMethodNonce' => $nonceFromTheClient]); if (!$payment->success) { $this->Session->setFlash($payment->message); $this->redirect(array('action' => 'payment')); } $payment = $payment->paymentMethod; } elseif (isset($this->request->data['payment_method']) && !empty($this->request->data['payment_method'])) { $payment = null; foreach ($customer->paymentMethods as $payment) { if ($payment->token == $this->request->data['payment_method']) { break; } } if (empty($payment)) { throw new NotFoundException(__d('billing', 'Payment method not found')); } } else { throw new NotFoundException(__d('billing', 'Unable to create subscription')); } $braintreePlanId = $this->Session->read('Billing.plan'); $plan = $this->BillingPlan->findByRemotePlan($braintreePlanId); $braintreePlans = Braintree_Plan::all(); $braintreePlan = null; foreach ($braintreePlans as $_braintreePlan) { if ($_braintreePlan->id == $braintreePlanId) { $braintreePlan = $_braintreePlan; break; } } if (empty($braintreePlan)) { throw new NotFoundException(__d('billing', 'Unable to create subscription')); } //Important! unit setup for model must be here. Before creating Braintree subscription $unit = Configure::read('Billing.units.' . $plan['BillingGroup']['limit_units']); if (empty($unit['model']) || empty($unit['field'])) { throw new NotFoundException(__d('billing', 'Invalid billing plan')); } $this->BillingSubscription->Behaviors->load('Billing.Limitable', array('remoteModel' => $unit['model'], 'remoteField' => $unit['field'], 'scope' => isset($unit['scope']) ? $unit['scope'] : 'user_id')); //Precreate subscription $braintreeData = array('paymentMethodToken' => $payment->token, 'planId' => $braintreePlanId); $qty = $this->Session->read('Billing.qty'); if (!empty($qty)) { if (empty($braintreePlan->addOns)) { throw new NotFoundException(__d('billing', 'Unable to create subscription')); } foreach ($braintreePlan->addOns as $addOn) { $braintreeData['addOns']['update'][] = array('existingId' => $addOn->id, 'quantity' => $qty); } } $billingSubscription = $this->BillingSubscription->find('first', array('conditions' => array('BillingSubscription.group_id' => $plan['BillingGroup']['id'], 'BillingSubscription.user_id' => $this->currUser['User']['id'], 'BillingSubscription.active' => true))); //braintree unable to update subscription to a plan with a different billing frequency So we need to cancel current if (!empty($billingSubscription)) { if ($braintreePlan->billingFrequency != $billingSubscription['BraintreePlan']->billingFrequency || $billingSubscription['BraintreeSubscription']->status == 'Canceled' || $billingSubscription['BraintreeSubscription']->status == 'Expired') { if ($braintreePlan->billingFrequency != $billingSubscription['BraintreePlan']->billingFrequency || $billingSubscription['BraintreeSubscription']->status != 'Canceled') { try { $result = Braintree_Subscription::cancel($billingSubscription['BraintreeSubscription']->id); if ($result->success) { $billingSubscription['BraintreeSubscription'] = $result->subscription; } } catch (Exception $e) { } } $status = isset($billingSubscription['BraintreeSubscription']->status) ? $billingSubscription['BraintreeSubscription']->status : 'Canceled'; $this->BillingSubscription->cancel($billingSubscription['BillingSubscription']['id'], $status); $billingSubscription = null; } } if (!isset($billingSubscription['BillingSubscription'])) { $data = array('group_id' => $plan['BillingGroup']['id'], 'plan_id' => $plan['BillingPlan']['id'], 'user_id' => $this->currUser['User']['id'], 'limit_value' => !empty($qty) ? $qty : $plan['BillingPlan']['limit_value'], 'active' => false); } else { $data = $billingSubscription['BillingSubscription']; $data['limit_value'] = !empty($qty) ? $qty : $plan['BillingPlan']['limit_value']; } //No Exceptions anymore! if (!isset($data['remote_subscription_id']) || empty($data['remote_subscription_id'])) { //Subscribe user by create $result = Braintree_Subscription::create($braintreeData); } else { $data['plan_id'] = $plan['BillingPlan']['id']; //Subscribe user by update $result = Braintree_Subscription::update($data['remote_subscription_id'], $braintreeData); } if (!$result->success) { $this->Session->setFlash(__d('billing', 'Unable to subscribe on chosen plan. Please contact with resorce administration')); $this->redirect(array('action' => 'plans', $plan['BillingGroup']['slug'])); } $data = Hash::merge($data, array('remote_subscription_id' => $result->subscription->id, 'remote_plan_id' => $result->subscription->planId, 'active' => $result->subscription->status === 'Active' ? true : false, 'status' => $result->subscription->status, 'expires' => $result->subscription->billingPeriodEndDate->format('Y-m-d H:i:s'), 'created' => $result->subscription->createdAt->format('Y-m-d H:i:s'), 'modified' => $result->subscription->updatedAt->format('Y-m-d H:i:s'))); if (!isset($data['id'])) { $this->BillingSubscription->create(); } if ($this->BillingSubscription->save($data)) { $this->Session->write('Billing'); if (!isset($data['id']) || empty($data['id'])) { $data['id'] = $this->BillingSubscription->getInsertID(); } $this->redirect(array('action' => 'success', $data['id'])); } else { $this->Session->setFlash(__d('billing', 'Unable to subscribe on chosen plan. Please contact with resorce administration')); $this->redirect(array('action' => 'plans', $plan['BillingGroup']['slug'])); } }
public function checkout() { $this->layout = 'profile_new'; if (!$this->request->is('post')) { throw new NotFoundException(__d('billing', 'Incorrect request type')); } $amount = $this->Session->read('Billing.amount'); $customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']); if (isset($this->request->data['payment_method_nonce'])) { $nonceFromTheClient = $this->request->data['payment_method_nonce']; $payment = Braintree_PaymentMethod::create(['customerId' => 'konstruktor-' . $this->currUser['User']['id'], 'paymentMethodNonce' => $nonceFromTheClient]); if (!$payment->success) { $this->Session->setFlash($payment->message); $this->redirect(array('action' => 'payment')); } $payment = $payment->paymentMethod; } elseif (isset($this->request->data['payment_method']) && !empty($this->request->data['payment_method'])) { $payment = null; foreach ($customer->paymentMethods as $payment) { if ($payment->token == $this->request->data['payment_method']) { break; } } if (empty($payment)) { throw new NotFoundException(__d('billing', 'Payment method not found')); } } else { throw new NotFoundException(__d('billing', 'Unable to create subscription')); } $result = Braintree_Transaction::sale(array('paymentMethodToken' => $payment->token, 'amount' => $amount, 'options' => array('submitForSettlement' => true))); if ($result->success) { $result = $result->transaction; $this->User->id = $this->currUser['User']['id']; $balance = $this->User->field('balance') + $amount; $userResult = $this->User->save(array('id' => $this->currUser['User']['id'], 'balance' => $balance)); //if(!$userResult){ //maybe support notification here //} } $this->redirect(array('plugin' => false, 'controller' => 'User', 'action' => 'view')); }
public function reservePayment() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $id_restaurant = $_GET["id_restaurant"]; $id_user = $_GET["id_user"]; $resto = new MasterRestaurantModel(); $resto->getByID($id_restaurant); $amount = 100000; if ($resto->verification_amount > 0) { $amount = $resto->verification_amount; } $user = new UserModel(); $user->getByID($id_user); if ($user->payment_id == null || $user->payment_id == "0") { Generic::errorMsg("No Payment Method"); } try { $result = Braintree_PaymentMethodNonce::create($user->braintree_id); $nonce = $result->paymentMethodNonce->nonce; } catch (Exception $e) { Generic::errorMsg($e->getMessage()); } $resultVerify = Braintree_PaymentMethod::create(['customerId' => $id_user, 'paymentMethodNonce' => $nonce, 'options' => ['verifyCard' => true, 'verificationMerchantAccountId' => 'm5ph2g77wgfzdyy2', 'verificationAmount' => $amount]]); $json["status_code"] = 0; if ($resultVerify) { $json["status_code"] = 1; $json['results']['amount'] = $amount; $json['results']['nonce'] = $nonce; } echo json_encode($json); die; }
public function checkoutReward() { if (!$this->request->is('post')) { throw new NotFoundException(__d('billing', 'Incorrect request type')); } $customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']); //TODO: payment nonce or id extrating in some places too. Refactoring needed if (isset($this->request->data['payment_method_nonce'])) { $nonceFromTheClient = $this->request->data['payment_method_nonce']; $payment = Braintree_PaymentMethod::create(['customerId' => 'konstruktor-' . $this->currUser['User']['id'], 'paymentMethodNonce' => $nonceFromTheClient]); if (!$payment->success) { $this->Session->setFlash($payment->message); $this->redirect(array('action' => 'payment')); } $payment = $payment->paymentMethod; } elseif (isset($this->request->data['payment_method']) && !empty($this->request->data['payment_method'])) { $payment = null; foreach ($customer->paymentMethods as $payment) { if ($payment->token == $this->request->data['payment_method']) { break; } } if (empty($payment)) { throw new NotFoundException(__('Payment method not found')); } } else { throw new NotFoundException(__('Unable to find payment method')); } $rewardId = $this->Session->read('InvestProject.RewardId'); $this->loadModel('InvestReward'); $this->InvestReward->Behaviors->load('Containable'); $investReward = $this->InvestReward->find('first', array('contain' => array('InvestProject'), 'conditions' => array('InvestReward.id' => $rewardId))); if (!$investReward) { throw new NotFoundException('Could not find investment reward for funds transfer'); } $result = Braintree_Transaction::sale(array('paymentMethodToken' => $payment->token, 'amount' => $investReward['InvestReward']['total'])); if (!$result->success) { $this->Session->setFlash(__('Unable to fund your money for chosen reward. Please contact with resource administration')); $this->redirect(array('action' => 'view', $investReward['InvestReward']['project_id'])); } $this->loadModel('InvestSponsor'); $this->InvestSponsor->create(); $data = array('user_id' => $this->currUserID, 'project_id' => $investReward['InvestReward']['project_id'], 'reward_id' => $investReward['InvestReward']['id'], 'amount' => $investReward['InvestReward']['total'], 'currency' => 'USD', 'remote_transaction_id' => $result->transaction->id); if (!$this->InvestSponsor->save($data)) { $result = Braintree_Transaction::void($result->transaction->id); $this->Session->setFlash(__('There is problem with sum funding. Your transaction has been cancelled.')); } else { $this->Session->setFlash(__('You are successfully invest in project')); } $this->redirect(array('action' => 'view', $investReward['InvestReward']['project_id'])); }