public function __construct(Am_Paysystem_CreditCard $plugin, $formType = self::PAYFORM) { $this->plugin = $plugin; $this->formType = $formType; $this->payButtons = array(self::PAYFORM => ___('Subscribe And Pay'), self::ADMIN_UPDATE => ___('Update Credit Card Info'), self::USER_UPDATE => ___('Update Credit Card Info'), self::ADMIN_INSERT => ___('Update Credit Card Info')); Am_Form::__construct('cc', array('action' => Braintree_TransparentRedirect::url())); }
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 }
$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 braintree_text_field('First Name', 'transaction[customer][first_name]', $result); ?> <?php braintree_text_field('Last Name', 'transaction[customer][last_name]', $result); ?> <?php braintree_text_field('Email', 'transaction[customer][email]', $result); ?> </fieldset>
function testUrl() { $url = Braintree_TransparentRedirect::url(); $developmentPort = getenv("GATEWAY_PORT") ? getenv("GATEWAY_PORT") : 3000; $this->assertEquals("http://localhost:" . $developmentPort . "/merchants/integration_merchant_id/transparent_redirect_requests", $url); }
public function url($url = NULL, $full = false) { return Braintree_TransparentRedirect::url(); }
function register_auto_payment_action($pack_id, $override_price = false, $return = true) { $this->_braintree(); global $current_user; get_currentuserinfo(); if ($current_user->ID) { $user_id = $current_user->ID; } else { $current_user = get_user_by('login', ym_request('username')); if ($current_user->ID) { $user_id = $current_user->ID; } else { echo 'bugger'; return; } } $customer_id = get_user_meta($user_id, 'ym_braintree_customer_id', true); if ($customer_id) { // validate the customer is still in braintree try { $customer = Braintree_Customer::find($customer_id); } catch (Exception $e) { $customer_id = false; } } if (!$customer_id) { // create required // shunt the customer into braintree $result = Braintree_Customer::create(array('id' => 'ym_' . $current_user->ID, 'email' => $current_user->user_email)); if ($result->success) { $customer_id = $result->customer->id; update_user_meta($user_id, 'ym_braintree_customer_id', $customer_id); } else { echo 'bugger'; return; } } $code = 'buy_subscription_' . $pack_id . '_' . $user_id; // credit card form driver $trData = Braintree_TransparentRedirect::updateCustomerData(array('redirectUrl' => site_url('?ym_process=' . $this->code . '&action=process&code=' . $code), 'customerId' => $customer_id)); $key = 'customer'; $html = ' <form action="' . Braintree_TransparentRedirect::url() . '" method="post" id="' . $this->code . '_cc_form_pack_' . $pack_id . '" class="' . $this->code . '_cc_form" autocomplete="off"> <input type="hidden" name="tr_data" value="' . htmlentities($trData) . '" /> <input type="hidden" name="code" value="' . $code . '" /> <div> <label for="braintree_credit_card_number">' . __('Credit Card Number', 'ym') . '</label> <input type="text" name="' . $key . '[credit_card][number]" id="braintree_credit_card_number" value=""></input> <label for="braintree_credit_card_ccv">' . __('Credit Card CCV', 'ym') . '</label> <input type="text" name="' . $key . '[credit_card][cvv]" id="braintree_credit_card_ccv" value=""></input> <label for="braintree_credit_card_exp">' . __('Credit Card Expiry (mm/yyyy)', 'ym') . '</label> <input type="text" size="7" maxlength="7" name="' . $key . '[credit_card][expiration_date]" id="braintree_credit_card_exp" value=""></input> </div> <input class="submit-button" type="submit" /> </form> '; if ($return) { return $html; } else { echo $html; return; } }