Ejemplo n.º 1
0
 public function updateAction()
 {
     $this->form = $this->createUpdateForm();
     if ($this->getParam('http_status') && $this->getParam('hash')) {
         $res = Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
         if ($res instanceof Braintree_Result_Error) {
             $this->form->getElementById('credit_card__number-0')->setError($res->message);
         } else {
             return $this->redirectLocation(REL_ROOT_URL . '/member');
         }
     }
     $this->view->form = $this->form;
     $this->view->invoice = null;
     $this->view->display_receipt = false;
     $this->view->display('cc/info.phtml');
 }
    public function form()
    {
        $result = Braintree_Transaction::sale(array("amount" => "1000.00", "creditCard" => array("number" => $_POST["number"], "cvv" => $_POST["cvv"], "expirationMonth" => $_POST["month"], "expirationYear" => $_POST["year"]), "options" => array("submitForSettlement" => true)));
        if ($result->success) {
            echo "Success! Transaction ID: " . $result->transaction->id;
        } else {
            if ($result->transaction) {
                echo "Error: " . $result->message;
                echo "<br/>";
                echo "Code: " . $result->transaction->processorResponseCode;
            } else {
                echo "Validation errors:<br/>";
                foreach ($result->errors->deepAll() as $error) {
                    echo "- " . $error->message . "<br/>";
                }
            }
        }
        pr($result);
        die;
        ?>
        <html>
            <head>
                <title>Braintree Transparent Redirect</title>
            </head>
            <body>
                <?php 
        if (isset($_GET["id"])) {
            echo "id: " . $_GET["id"];
            $result = Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
            pr($result);
        }
        if (isset($result) && $result->success) {
            ?>
                    <h1>Braintree Transparent Redirect Response</h1>
                    <?php 
            $transaction = $result->transaction;
            ?>
                    <table>
                        <tr><td>transaction id</td><td><?php 
            echo htmlentities($transaction->id);
            ?>
</td></tr>
                        <tr><td>transaction status</td><td><?php 
            echo htmlentities($transaction->status);
            ?>
</td></tr>
                        <tr><td>transaction amount</td><td><?php 
            echo htmlentities($transaction->amount);
            ?>
</td></tr>
                        <tr><td>customer first name</td><td><?php 
            echo htmlentities($transaction->customerDetails->firstName);
            ?>
</td></tr>
                        <tr><td>customer last name</td><td><?php 
            echo htmlentities($transaction->customerDetails->lastName);
            ?>
</td></tr>
                        <tr><td>customer email</td><td><?php 
            echo htmlentities($transaction->customerDetails->email);
            ?>
</td></tr>
                        <tr><td>credit card number</td><td><?php 
            echo htmlentities($transaction->creditCardDetails->maskedNumber);
            ?>
</td></tr>
                        <tr><td>expiration date</td><td><?php 
            echo htmlentities($transaction->creditCardDetails->expirationDate);
            ?>
</td></tr>
                    </table>
                    <?php 
        } else {
            if (!isset($result)) {
                echo "gagal";
                $result = null;
            }
            ?>
                    <h1>Braintree Transparent Redirect Example</h1>
                    <?php 
            if (isset($result)) {
                ?>
                        <div style="color: red;"><?php 
                echo $result->errors->deepSize();
                ?>
 error(s)</div>
                    <?php 
            }
            ?>
                    <form method="POST" action="<?php 
            echo Braintree_TransparentRedirect::url();
            ?>
" autocomplete="off">
                        <fieldset>
                            <legend>Customer</legend>
                            <?php 
            $this->braintree_text_field('First Name', 'transaction[customer][first_name]', $result);
            ?>
                            <?php 
            $this->braintree_text_field('Last Name', 'transaction[customer][last_name]', $result);
            ?>
                            <?php 
            $this->braintree_text_field('Email', 'transaction[customer][email]', $result);
            ?>
                        </fieldset>

                        <fieldset>
                            <legend>Payment Information</legend>

                            <?php 
            $this->braintree_text_field('Credit Card Number', 'transaction[credit_card][number]', $result);
            ?>
                            <?php 
            $this->braintree_text_field('Expiration Date (MM/YY)', 'transaction[credit_card][expiration_date]', $result);
            ?>
                            <?php 
            $this->braintree_text_field('CVV', 'transaction[credit_card][cvv]', $result);
            ?>
                        </fieldset>

                        <?php 
            $tr_data = Braintree_TransparentRedirect::transactionData(array('redirectUrl' => "http://" . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), 'transaction' => array('amount' => '10.00', 'type' => 'sale')));
            ?>
                        <input type="hidden" name="tr_data" value="<?php 
            echo $tr_data;
            ?>
" />

                        <br />
                        <input type="submit" value="Submit" />
                    </form>
                <?php 
        }
        ?>
            </body>
        </html>
        <?php 
    }
Ejemplo n.º 3
0
<?php

$queryString = $_SERVER['QUERY_STRING'];
$result = Braintree_TransparentRedirect::confirm($queryString);
if ($result->success) {
    $message = "Customer Created with ID: " . $result->customer->email;
} else {
    $message = print_r($result->errors->deepAll(), True);
}
?>

<html>
  <body>
    <h1>Transaction Response</h1>
    <ul>
      <li>Status - <?php 
echo $message;
?>
</li>
    </ul>
  </body>
</html>
Ejemplo n.º 4
0
    echo '<div><input type="text" name="' . $name . '" value="' . $fieldValue . '" /></div>';
    $errors = isset($result) ? $result->errors->onHtmlField($name) : array();
    foreach ($errors as $error) {
        echo '<div style="color: red;">' . $error->message . '</div>';
    }
    echo "\n";
}
?>
<html>
<head>
    <title>Braintree Transparent Redirect</title>
</head>
<body>
<?php 
if (isset($_GET["id"])) {
    $result = Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
}
if (isset($result) && $result->success) {
    ?>
<h1>Braintree Transparent Redirect Response</h1>
    <?php 
    $transaction = $result->transaction;
    ?>
<table>
    <tr><td>transaction id</td><td><?php 
    echo htmlentities($transaction->id);
    ?>
</td></tr>
    <tr><td>transaction status</td><td><?php 
    echo htmlentities($transaction->status);
    ?>
 function testUpdateCreditCardFromTransparentRedirect()
 {
     $customer = Braintree_Customer::create(array('firstName' => 'Mike', 'lastName' => 'Jonez'))->customer;
     $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => Braintree_Test_CreditCardNumbers::$masterCard, 'expirationMonth' => '10', 'expirationYear' => '10'))->creditCard;
     $params = array('credit_card' => array('number' => Braintree_Test_CreditCardNumbers::$visa));
     $trParams = array('paymentMethodToken' => $creditCard->token, 'creditCard' => array('expirationMonth' => '11', 'expirationYear' => '11'));
     $trData = Braintree_TransparentRedirect::updateCreditCardData(array_merge($trParams, array("redirectUrl" => "http://www.example.com")));
     $queryString = Braintree_TestHelper::submitTrRequest(Braintree_TransparentRedirect::url(), $params, $trData);
     Braintree_TransparentRedirect::confirm($queryString);
     $creditCard = Braintree_CreditCard::find($creditCard->token);
     $this->assertequals('401288', $creditCard->bin);
     $this->assertequals('1881', $creditCard->last4);
     $this->assertequals('11/2011', $creditCard->expirationDate);
 }
 public function confirm()
 {
     try {
         return Braintree_TransparentRedirect::confirm($_SERVER['QUERY_STRING']);
     } catch (Braintree_Exception $e) {
         Mage::logException($e);
         $result = stdClass;
         $result->success = false;
         return $result;
     }
 }
 /**
  * Startup
  *
  * @param   object  $controller
  * @return  void
  */
 public function startup(Controller $controller)
 {
     if (in_array($this->controller->params['action'], $this->_callback_actions) || array_key_exists($this->controller->params['action'], $this->_callback_actions)) {
         $this->action_settings = array();
         if (!empty($this->_callback_actions[$this->controller->params['action']]) && is_array($this->_callback_actions[$this->controller->params['action']])) {
             $this->action_settings = $this->_callback_actions[$this->controller->params['action']];
         }
         $continue = true;
         $parameters = array();
         foreach ($this->_callback_parameters as $parameter) {
             if (empty($this->controller->params['url'][$parameter])) {
                 $continue = false;
                 break;
             } else {
                 $parameters[$parameter] = $this->controller->params['url'][$parameter];
             }
         }
         if ($continue) {
             App::import('Vendor', 'Braintree.Braintree');
             $query_string = http_build_query($parameters, '', '&');
             foreach (array('BraintreeAddress', 'BraintreeCreditCard', 'BraintreeCreditCardRelation') as $model_name) {
                 if (!isset($this->{$model_name})) {
                     $this->{$model_name} = ClassRegistry::init('Braintree.' . $model_name);
                 }
             }
             if (!$this->beforeConfirmation()) {
                 return false;
             }
             try {
                 $result = Braintree_TransparentRedirect::confirm($query_string);
             } catch (Exception $e) {
                 $result = false;
             }
             if (empty($result) || !$result->success) {
                 $this->onFailure($result);
                 return true;
             } else {
                 if (!$this->onSuccess($result)) {
                     return true;
                 }
             }
             if (!$this->afterProcessing()) {
                 return false;
             }
         }
     }
 }
Ejemplo n.º 8
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();
                }
            }
        }
    }