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);
 }
 public function check($customer)
 {
     if (empty($customer)) {
         $customer = $this->_controller->currUser;
     }
     $firstName = $lastName = '';
     $name = explode(' ', $customer['User']['full_name']);
     if (count($name) > 0) {
         $firstName = array_shift($name);
         $lastName = implode(' ', $name);
     }
     $customerData = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $customer['User']['username'], 'phone' => $customer['User']['phone']);
     try {
         $_customer = Braintree_Customer::find('konstruktor-' . $customer['User']['id']);
         $_customer = Braintree_Customer::update('konstruktor-' . $customer['User']['id'], $customerData);
     } catch (Exception $e) {
         $_customer = Braintree_Customer::create(Hash::merge(array('id' => 'konstruktor-' . $customer['User']['id']), $customerData));
     }
     if ($_customer->success) {
         return $_customer->customer;
     }
     return array();
 }
 function getCustomer(&$order, $force = false)
 {
     global $current_user;
     //already have it?
     if (!empty($this->customer) && !$force) {
         return $this->customer;
     }
     //try based on user id
     if (!empty($order->user_id)) {
         $user_id = $order->user_id;
     }
     //if no id passed, check the current user
     if (empty($user_id) && !empty($current_user->ID)) {
         $user_id = $current_user->ID;
     }
     //check for a braintree customer id
     if (!empty($user_id)) {
         $customer_id = get_user_meta($user_id, "pmpro_braintree_customerid", true);
     }
     //check for an existing stripe customer
     if (!empty($customer_id)) {
         try {
             $this->customer = Braintree_Customer::find($customer_id);
             //update the customer address, description and card
             if (!empty($order->accountnumber)) {
                 //put data in array for Braintree API calls
                 $update_array = array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'creditCard' => array('number' => $order->braintree->number, 'expirationDate' => $order->braintree->expiration_date, 'cardholderName' => trim($order->FirstName . " " . $order->LastName), 'options' => array('updateExistingToken' => $this->customer->creditCards[0]->token)));
                 //address too?
                 if (!empty($order->billing)) {
                     //make sure Address2 is set
                     if (!isset($order->Address2)) {
                         $order->Address2 = '';
                     }
                 }
                 //add billing address to array
                 $update_array['creditCard']['billingAddress'] = array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'streetAddress' => $order->Address1, 'extendedAddress' => $order->Address2, 'locality' => $order->billing->city, 'region' => $order->billing->state, 'postalCode' => $order->billing->zip, 'countryCodeAlpha2' => $order->billing->country, 'options' => array('updateExisting' => true));
                 //update
                 $response = Braintree_Customer::update($customer_id, $update_array);
                 if ($response->success) {
                     $this->customer = $response->customer;
                     return $this->customer;
                 } else {
                     $order->error = __("Failed to update customer.", "pmpro") . " " . $response->message;
                     $order->shorterror = $order->error;
                     return false;
                 }
             }
             return $this->customer;
         } catch (Exception $e) {
             //assume no customer found
         }
     }
     //no customer id, create one
     if (!empty($order->accountnumber)) {
         try {
             $result = Braintree_Customer::create(array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'email' => $order->Email, 'phone' => $order->billing->phone, 'creditCard' => array('number' => $order->braintree->number, 'expirationDate' => $order->braintree->expiration_date, 'cvv' => $order->braintree->cvv, 'cardholderName' => trim($order->FirstName . " " . $order->LastName), 'billingAddress' => array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'streetAddress' => $order->Address1, 'extendedAddress' => $order->Address2, 'locality' => $order->billing->city, 'region' => $order->billing->state, 'postalCode' => $order->billing->zip, 'countryCodeAlpha2' => $order->billing->country))));
             if ($result->success) {
                 $this->customer = $result->customer;
             } else {
                 $order->error = __("Failed to create customer.", "pmpro") . " " . $result->message;
                 $order->shorterror = $order->error;
                 return false;
             }
         } catch (Exception $e) {
             $order->error = __("Error creating customer record with Braintree:", "pmpro") . " " . $e->getMessage();
             $order->shorterror = $order->error;
             return false;
         }
         //if we have no user id, we need to set the customer id after the user is created
         if (empty($user_id)) {
             global $pmpro_braintree_customerid;
             $pmpro_braintree_customerid = $this->customer->id;
             add_action('user_register', array('PMProGateway_braintree', 'user_register'));
         } else {
             update_user_meta($user_id, "pmpro_braintree_customerid", $this->customer->id);
         }
         return $this->customer;
     }
     return false;
 }
 /**
  * Updates customer ID
  * 
  * @param string $customerId
  * @param string $newId
  */
 public function updateCustomerId($customerId, $newId)
 {
     if ($this->exists($customerId)) {
         $this->_debug("Updating customer ID {$customerId} to {$newId}");
         try {
             $result = Braintree_Customer::update($customerId, array('id' => $newId));
         } catch (Exception $e) {
             Mage::logException($e);
             $result = 'Update failed';
         }
         $this->_debug($result);
     }
 }
Esempio n. 5
0
     //[ADD Customer ID to text file]
     $customer = $result->customer->id . "\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, $customer, FILE_APPEND | LOCK_EX);
     echo "</br>";
     echo "<div> <h3>API response</h3>";
     //echo json_encode($result, JSON_PRETTY_PRINT);
     //echo json_encode($result);
     echo "<pre>";
     print_r($result);
     echo "</div>";
 } else {
     if ($_POST['_act'] == 'updateCustomer') {
         $updateResult = Braintree_Customer::update($_POST['customer_id'], array('firstName' => $_POST['firstName'], 'lastName' => $_POST['lastName'], 'company' => $_POST['company'], 'email' => $_POST['email'], 'phone' => $_POST['phone'], 'fax' => $_POST['fax'], 'website' => $_POST['website']));
         $updateResult->success;
         print_r($updateResult);
     } else {
         if ($_POST['_act'] == 'findCustomer') {
             //echo $_POST['customer_id'];
             //$_POST['customer_id'] = '57306224';
             $findResult = Braintree_Customer::find((string) $_POST['customer_id']);
             print_r($findResult);
         } else {
             if ($_POST['_act'] == 'deleteCustomer') {
                 $search = (string) $_POST['customer_id'];
                 $file = './data/customerID.txt';
                 $contents = file_get_contents($file);
                 echo $contents = str_replace($_POST['customer_id'], trim((string) $_POST['customer_id'] . "_DELETED\r\n"), $contents);
                 file_put_contents($file, $contents);
 function getCustomer(&$order, $force = false)
 {
     global $current_user;
     //already have it?
     if (!empty($this->customer) && !$force) {
         return $this->customer;
     }
     //try based on user id
     if (!empty($order->user_id)) {
         $user_id = $order->user_id;
     }
     //if no id passed, check the current user
     if (empty($user_id) && !empty($current_user->ID)) {
         $user_id = $current_user->ID;
     }
     //check for a braintree customer id
     if (!empty($user_id)) {
         $customer_id = get_user_meta($user_id, "pmpro_braintree_customerid", true);
     }
     //check for an existing stripe customer
     if (!empty($customer_id)) {
         try {
             $this->customer = Braintree_Customer::find($customer_id);
             //update the customer description and card
             if (!empty($order->accountnumber)) {
                 $response = Braintree_Customer::update($customer_id, array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'creditCard' => array('number' => $order->braintree->number, 'expirationDate' => $order->braintree->expiration_date, 'cardholderName' => trim($order->FirstName . " " . $order->LastName), 'options' => array('updateExistingToken' => $customer_id))));
                 if ($response->success) {
                     $this->customer = $result->customer;
                 } else {
                     $order->error = __("Failed to update customer.", "pmpro");
                     $order->shorterror = $order->error;
                     return false;
                 }
             }
             return $this->customer;
         } catch (Exception $e) {
             //assume no customer found
         }
     }
     //no customer id, create one
     if (!empty($order->accountnumber)) {
         try {
             $result = Braintree_Customer::create(array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'email' => $order->Email, 'phone' => $order->billing->phone, 'creditCard' => array('number' => $order->braintree->number, 'expirationDate' => $order->braintree->expiration_date, 'cvv' => $order->braintree->cvv, 'cardholderName' => trim($order->FirstName . " " . $order->LastName), 'billingAddress' => array('firstName' => $order->FirstName, 'lastName' => $order->LastName, 'streetAddress' => $order->Address1, 'extendedAddress' => $order->Address2, 'locality' => $order->billing->city, 'region' => $order->billing->state, 'postalCode' => $order->billing->zip, 'countryCodeAlpha2' => $order->billing->country))));
             if ($result->success) {
                 $this->customer = $result->customer;
             } else {
                 $order->error = __("Failed to create customer.", "pmpro");
                 $order->shorterror = $order->error;
                 return false;
             }
         } catch (Exception $e) {
             $order->error = __("Error creating customer record with Braintree:", "pmpro") . " " . $e->getMessage();
             $order->shorterror = $order->error;
             return false;
         }
         update_user_meta($user_id, "pmpro_braintree_customerid", $this->customer->id);
         return $this->customer;
     }
     return false;
 }
 /**
  * Updates an existing record via the API
  *
  * @param   object  $model
  * @param   array   $fields
  * @param   array   $values
  * @return  bool
  */
 public function update(Model $model, $fields = null, $values = null, $conditions = null)
 {
     $to_save = $this->_createSaveArray($fields, $values);
     if (!empty($to_save['id'])) {
         $model->id = $to_save['id'];
         unset($to_save['id']);
     }
     if (empty($model->id)) {
         false;
     }
     $entity = $this->_getModelEntity($model);
     try {
         switch ($entity) {
             case 'Customer':
                 $result = Braintree_Customer::update($model->id, $to_save);
                 break;
             case 'Transaction':
                 $transaction = $this->read($model, array('conditions' => array($model->alias . '.' . $model->primaryKey => $model->id)));
                 if (empty($transaction)) {
                     return false;
                 }
                 $exploded = explode('|', $model->id);
                 $braintree_transaction_id = isset($exploded[1]) ? $exploded[1] : $model->id;
                 if (!empty($to_save['status']) && $to_save['status'] == 'voided') {
                     if ($transaction[0][$model->alias]['status'] != 'authorized' && $transaction[0][$model->alias]['status'] != 'submitted_for_settlement') {
                         $this->showError(__('A transaction can only be VOIDED when the status is AUTHORIZED or SUBMITTED FOR SETTLEMENT.', true));
                         return false;
                     }
                     $result = Braintree_Transaction::void($braintree_transaction_id);
                     if (!$result->success) {
                         $this->showError($result->message);
                         return false;
                     }
                 } elseif (!empty($to_save['status']) && $to_save['status'] == 'submitted_for_settlement') {
                     if ($transaction[0][$model->alias]['status'] != 'authorized') {
                         $this->showError(__('A transaction can only be SUBMITTED FOR SETTLEMENT when the status is AUTHORIZED.', true));
                         return false;
                     }
                     if (!empty($to_save['amount'])) {
                         $result = Braintree_Transaction::submitForSettlement($braintree_transaction_id, $to_save['amount']);
                     } else {
                         $result = Braintree_Transaction::submitForSettlement($braintree_transaction_id);
                     }
                     if (!$result->success) {
                         $this->showError($result->message);
                         return false;
                     }
                 } else {
                     $this->showError(__('The only update that can be made to a transaction is a VOID.', true));
                     return false;
                 }
                 break;
             case 'CreditCard':
                 return false;
                 break;
             case 'Address':
                 return false;
                 break;
             default:
                 $result = false;
                 break;
         }
     } catch (Exception $e) {
         $this->showError(print_r($e, true));
         return false;
     }
     $success = $result->success;
     if (!$success) {
         return false;
     }
     return $success;
 }
 /**
  * Updates customer id
  * 
  * @param string $customerId
  * @param string $email
  */
 protected function _updateCustomer($customerId, $email, $newId = false)
 {
     if (!$newId) {
         $newId = Mage::helper('braintree_payments')->generateCustomerId($customerId, $email);
     }
     try {
         Braintree_Customer::update($customerId, array('id' => $newId));
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Esempio n. 9
0
    function do_process()
    {
        $action = ym_request('action');
        if ($action == 'js') {
            header('Content-Type: text/javascript');
            ?>
jQuery(document).ready(function() {
	jQuery('.ym_braintree_button').click(function(event) {
		event.preventDefault();

		jQuery('.ym_form').slideUp();
		jQuery('#<?php 
            echo $this->code;
            ?>
_cc_form_unique_' + jQuery(this).attr('data-unique')).slideDown();
	});

	var braintree = Braintree.create("<?php 
            echo $this->encryptionkey;
            ?>
");
	jQuery('.<?php 
            echo $this->code;
            ?>
_cc_form').submit(function(e) {
		e.preventDefault();

		jQuery('.ym_braintree_icon').addClass('ym_ajax_loading_image');

		var target = jQuery(this);
		target.find('.error').remove();

		var data = jQuery(this).clone();
		data.find('#braintree_credit_card_number').val(braintree.encrypt(jQuery(this).find('#braintree_credit_card_number').val()));
		data.find('#braintree_credit_card_ccv').val(braintree.encrypt(jQuery(this).find('#braintree_credit_card_ccv').val()));
		data.find('#braintree_credit_card_exp').val(braintree.encrypt(jQuery(this).find('#braintree_credit_card_exp').val()));

		target.find('input').attr('disabled', 'disabled');

		jQuery.post('<?php 
            echo $this->action_url;
            ?>
&action=ajax', data.serialize(), function(resp) {
			jQuery('.ym_braintree_icon').removeClass('ym_ajax_loading_image');

			resp = jQuery.parseJSON(resp);
			if (resp['ok']) {
				target.find('#braintree_credit_card_number').val('');
				target.find('#braintree_credit_card_ccv').val('');
				target.find('#braintree_credit_card_exp').val('');

				jQuery('<div class="success"><p>' + resp['message'] + '</p></div>').prependTo(target);

				document.location = resp['url'];
			} else {
				target.find('input').removeAttr('disabled');
				jQuery('<div class="error"><p>' + resp['message'] + '</p></div>').prependTo(target);
			}
		});
	});
});
<?php 
            exit;
        } else {
            if ($action == 'ajax') {
                ob_start();
                $this->_braintree();
                // issue sale or subscribe
                $code = $_POST['code'];
                list($buy, $what, $pack_id, $user_id) = explode('_', $code);
                // credit card update
                $result = Braintree_Customer::update('ym_' . $user_id, array('creditCard' => array('number' => $_POST['customer']['credit_card']['number'], 'cvv' => $_POST['customer']['credit_card']['cvv'], 'expirationDate' => $_POST['customer']['credit_card']['expiration_date'])));
                if ($result->success) {
                    // grab token and subscribe
                    //				if ($pack['num_cycles'] == 1 || $planId) {
                    if ($what == 'subscription') {
                        // above catches both kinds of package/subscription
                        $pack = ym_get_pack_by_id($pack_id);
                        $planId = isset($pack['braintree_plan_id']) ? $pack['braintree_plan_id'] : false;
                        // initiate charge against just added credit card
                        if ($planId) {
                            $result = Braintree_Subscription::create(array('planId' => $planId, 'paymentMethodToken' => $result->customer->creditCards[0]->token));
                            $amount = $result->subscription->transactions[0]->amount;
                        } else {
                            $result = Braintree_Transaction::sale(array('amount' => $pack['cost'], 'options' => array('submitForSettlement' => true), 'customerId' => $result->customer->id, 'paymentMethodToken' => $result->customer->creditCards[0]->token));
                            $amount = $result->transaction->amount;
                        }
                        if ($result->success) {
                            // common
                            $this->common_process($code, $amount, true, false);
                            // thanks
                            $url = $this->redirectlogic($pack);
                            $r = array('ok' => true, 'url' => $url, 'message' => __('Payment Complete', 'ym'));
                        } else {
                            $r = $this->_failedBraintree($result, true);
                        }
                    } else {
                        if ($what == 'bundle' || $what == 'post') {
                            // post or bundle purchase
                            if ($what == 'post') {
                                $cost = get_post_meta($pack_id, '_ym_post_purchasable_cost', true);
                            } else {
                                $bundle = ym_get_bundle($pack_id);
                                if (!$bundle) {
                                    $r = array('ok' => false, 'message' => __('Bundle Error', 'ym'));
                                } else {
                                    $cost = $bundle->cost;
                                }
                            }
                            if ($cost) {
                                $result = Braintree_Transaction::sale(array('amount' => $cost, 'options' => array('submitForSettlement' => true), 'customerId' => $result->customer->id, 'paymentMethodToken' => $result->customer->creditCards[0]->token));
                                $amount = $result->transaction->amount;
                                if ($result->success) {
                                    // common
                                    $this->common_process($code, $amount, true, false);
                                    // thanks
                                    if ($what == 'subscription') {
                                        $url = $this->redirectlogic($pack);
                                    } else {
                                        if ($what == 'post') {
                                            $url = $this->redirectlogic(array('ppp' => true, 'post_id' => $pack_id));
                                        } else {
                                            $url = $this->redirectlogic(array('ppp' => true, 'ppp_pack_id' => $pack_id));
                                        }
                                    }
                                    $r = array('ok' => true, 'url' => $url, 'message' => __('Payment Complete', 'ym'));
                                } else {
                                    $r = $this->_failedBraintree($result, true);
                                }
                            }
                        } else {
                            // unhandled purchase
                            $r = $this->_failedBraintree($result, true);
                        }
                    }
                } else {
                    $r = $this->_failedBraintree($result, true);
                }
                ob_clean();
                echo json_encode($r);
                // bugger
                exit;
                // non ajax/primary js failed
                // transparent redirect handlers
            } else {
                if ($action == 'process') {
                    $this->_braintree();
                    $queryString = $_SERVER['QUERY_STRING'];
                    try {
                        $result = Braintree_TransparentRedirect::confirm($queryString);
                    } catch (Exception $e) {
                        if (get_class($e) == 'Braintree_Exception_NotFound') {
                            echo 'not found';
                        } else {
                            echo '<pre>';
                            print_r($e);
                            echo $e->getMessage();
                        }
                        exit;
                    }
                    if ($result->success) {
                        $code = ym_request('code');
                        // grab token and subscribe
                        list($buy, $what, $pack_id, $user_id) = explode('_', $code);
                        $pack = ym_get_pack_by_id($pack_id);
                        $planId = isset($pack['braintree_plan_id']) ? $pack['braintree_plan_id'] : false;
                        if ($pack['num_cycles'] == 1 || $planId) {
                            // initiate charge against just added credit card
                            if ($planId) {
                                $result = Braintree_Subscription::create(array('planId' => $planId, 'paymentMethodToken' => $result->customer->creditCards[0]->token));
                                $amount = $result->subscription->transactions[0]->amount;
                            } else {
                                $result = Braintree_Transaction::sale(array('amount' => $pack['cost'], 'options' => array('submitForSettlement' => true), 'customerId' => $result->customer->id, 'paymentMethodToken' => $result->customer->creditCards[0]->token));
                                $amount = $result->transaction->amount;
                            }
                            if ($result->success) {
                                // common
                                $this->common_process($code, $amount, true, false);
                                // thanks
                                $this->redirectlogic($pack, true);
                                exit;
                            } else {
                                $this->_failedBraintree($result);
                            }
                        } else {
                            $this->_failedBraintree($result);
                        }
                        exit;
                    }
                    $this->_failedBraintree($result);
                } else {
                    $this->_failedBraintree();
                }
            }
        }
    }
Esempio n. 10
0
 function testUpdate_withNewCreditCardAndExistingBillingAddress()
 {
     $customer = Braintree_Customer::create()->customer;
     $address = Braintree_Address::create(array('customerId' => $customer->id, 'firstName' => 'Dan'))->address;
     $result = Braintree_Customer::update($customer->id, array('creditCard' => array('number' => '4111111111111111', 'expirationDate' => '11/14', 'billingAddressId' => $address->id)));
     $billingAddress = $result->customer->creditCards[0]->billingAddress;
     $this->assertEquals($address->id, $billingAddress->id);
     $this->assertEquals('Dan', $billingAddress->firstName);
 }
 public function update()
 {
     $updateResult = Braintree_Customer::update('2', ['firstName' => 'New First', 'lastName' => 'New Last', 'company' => 'New Company', 'email' => '*****@*****.**', 'phone' => 'new phone', 'fax' => 'new fax', 'website' => 'http://new.example.com']);
     $updateResult->success;
     pr($updateResult);
 }
Esempio n. 12
0
 public function updateCustomer($id, $data)
 {
     $result = Braintree_Customer::update($id, $data);
     echo "<pre>";
     print_r($result);
     echo "</pre>";
     if ($result->success) {
         return array('success' => 1, 'customer_id' => $result->customer->id);
     } else {
         return array('success' => 0, 'validation_errors' => $errors);
     }
 }
 function testUpdate_forBillingAddressAndExistingCreditCardAndCustomerDetailsTogether()
 {
     $create_result = Braintree_Customer::create(array('firstName' => 'Old First', 'lastName' => 'Old Last', 'creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12', 'cvv' => '123', 'cardholderName' => 'Old Cardholder', 'billingAddress' => array('firstName' => 'Drew', 'lastName' => 'Smith'))));
     $this->assertEquals(true, $create_result->success);
     $customer = $create_result->customer;
     $creditCard = $customer->creditCards[0];
     $result = Braintree_Customer::update($customer->id, array('firstName' => 'New Customer First', 'lastName' => 'New Customer Last', 'creditCard' => array('number' => '4111111111111111', 'expirationDate' => '11/14', 'options' => array('updateExistingToken' => $creditCard->token), 'billingAddress' => array('firstName' => 'New Billing First', 'lastName' => 'New Billing Last', 'options' => array('updateExisting' => true)))));
     $this->assertEquals(true, $result->success);
     $this->assertEquals('New Customer First', $result->customer->firstName);
     $this->assertEquals('New Customer Last', $result->customer->lastName);
     $this->assertEquals(1, sizeof($result->customer->creditCards));
     $this->assertEquals(1, sizeof($result->customer->addresses));
     $creditCard = $result->customer->creditCards[0];
     $this->assertEquals('411111', $creditCard->bin);
     $this->assertEquals('11/2014', $creditCard->expirationDate);
     $billingAddress = $creditCard->billingAddress;
     $this->assertEquals('New Billing First', $billingAddress->firstName);
     $this->assertEquals('New Billing Last', $billingAddress->lastName);
 }
Esempio n. 14
0
 function testUpdate_doesNotWorkWithOnetimePayPalNonce()
 {
     $customerResult = Braintree_Customer::create(array('creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12', 'options' => array('makeDefault' => true))));
     $paypalAccountToken = 'PAYPALToken-' . strval(rand());
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('access_token' => 'PAYPAL_ACCESS_TOKEN', 'token' => $paypalAccountToken, 'options' => array('makeDefault' => true))));
     $result = Braintree_Customer::update($customerResult->customer->id, array('paymentMethodNonce' => $nonce));
     $this->assertFalse($result->success);
     $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
     $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
 }
Esempio n. 15
0
 $phone = filter_var($phone, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\(?(\\d{3})\\)?[-\\. ]?(\\d{3})[-\\. ]?(\\d{4})\$/")));
 if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\(?(\\d{3})\\)?[-\\. ]?(\\d{3})[-\\. ]?(\\d{4})\$/")))) {
     // Not a valid US phone number
     echo 'The phone number you entered is not a valid US phone number<br><br><input type="button" value="Submit" onClick="doChangeBill();">';
     exit;
 }
 $expd = filter_input(INPUT_POST, 'expd', FILTER_SANITIZE_STRING);
 $cardn = "";
 // Verify Zip with Braintree first
 $customer = Braintree_Customer::find($un . "_FITNESS");
 $successful = false;
 if ($customer->id !== "") {
     $payToken = $customer->creditCards[0]->token;
     if (@isset($_POST['nonce'])) {
         $nonce = filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING);
         $result = Braintree_Customer::update($un . "_FITNESS", array('creditCard' => array('paymentMethodNonce' => $nonce, 'options' => array('updateExistingToken' => $payToken))));
         if ($result->success) {
             $successful = true;
             $cardn = $result->customer->creditCards[0]->maskedNumber;
             $expd = $result->customer->creditCards[0]->expirationDate;
         } else {
             $error_msg = 'Update failed:';
             foreach ($result->errors->deepAll() as $error) {
                 $error_msg .= $error->code . ": " . $error->message . '<br>';
             }
             echo $error_msg . '<br><br><input type="button" value="Submit" onClick="doChangeBill();">';
             exit;
         }
     } else {
         $result = Braintree_PaymentMethod::update($payToken, array('billingAddress' => array('postalCode' => $zip, 'options' => array('updateExisting' => true)), 'expirationDate' => $expd));
         if ($result->success) {
 public function updatePaymentMethod()
 {
     $nonce = $_POST["nonce"];
     $aCustomerId = $_POST["id_user"];
     $updateResult = Braintree_Customer::update($aCustomerId, ['paymentMethodNonce' => $nonce]);
     if ($updateResult->success) {
         echo "{\"status_code\":1,\"results\":{\"update_status\":\"success\"}}";
     } else {
         echo "{\"status_code\":0,\"results\":{\"update_status\":\"failed\"}}";
     }
     die;
 }
Esempio n. 17
0
<?php

require 'template/header.php';
require 'credentials.php';
use fzaninotto\faker\src;
// add payment nonce to customer
if (isset($_POST['payment_method_nonce']) && isset($_GET['id'])) {
    $updateCustomer = Braintree_Customer::update($_GET['id'], ["paymentMethodNonce" => $_POST['payment_method_nonce']]);
    if ($updateCustomer->success) {
        echo '<div class="alert alert-success" role="alert">Payment Method Added</div>';
    } else {
        echo "<div class='alert alert-danger' role='alert'>{$updateCustomer->message}</div>";
    }
}
// generate new customer
if (isset($_GET['action']) && $_GET['action'] == 'generateNewCustomer') {
    $faker = Faker\Factory::create();
    $firstName = $faker->firstName;
    $lastName = $faker->lastName;
    $createCustomer = Braintree_Customer::create(['firstName' => $firstName, 'lastName' => $lastName, 'company' => $faker->company, 'email' => $firstName . "." . $lastName . "@dummy.com", 'phone' => $faker->phoneNumber, 'fax' => $faker->phoneNumber]);
    if ($createCustomer->success) {
        echo '<div class="alert alert-success" role="alert">Customer "' . $firstName . " " . $lastName . '" is generated.</div>';
    } else {
        echo "<div class='alert alert-danger' role='alert'>{$createCustomer->message}</div>";
    }
}
// continue loading customers page
$now = new DateTime();
$past = clone $now;
$past = $past->modify("-5 month");
$customerCollection = Braintree_Customer::search([Braintree_CustomerSearch::createdAt()->between($past, $now)]);