Reputation: 134
I am trying to setup Braintree hosted fields on my registration form. But the fields have massive gaps between them and it just doesn't look right. I've tried using the braintree documentation and guides but they are extremely vague.
I would consider myself a intermediate web developer and would say I have a good knowledge of php, html and css. I have little understanding of javascript but can use it a little bit but not where near as good an understanding as I have for PHP.
Could you guy's point me in the right direction to get the payment page looking right? I need the elements to look like the first 2 parts of the registration page..
Please note the form does not submit yet, I'm still working on the look and feel. But once braintree is integrated its just a matter of capturing the form data and submitting it to the database.
Here is the link to the form: http://www.mcr-qr-time.com/registration-form/register.html?plan=1
and see code below:(I have API keys edited out)
<?php
$plan = $_GET['plan'];
if($plan == "1"){
$amount = "4.99";
}
if($plan == "2"){
$amount = "14.99";
}
if($plan == "3"){
$amount = "34.99";
}
require_once 'braintree-php-3.9.0/lib/Braintree.php';
Braintree_Configuration::environment('production');
Braintree_Configuration::merchantId('#');
Braintree_Configuration::publicKey('#');
Braintree_Configuration::privateKey('#');
if(isset($_POST['submit'])){
/* process transaction */
$result = Braintree_Transaction::sale(array(
'amount' => $amount,
'creditCard' => array(
'number' => '(dont know what to do here)',
'expirationDate' => '(dont know what to do here)'
)
));
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
print_r("Validation errors: \n");
print_r($result->errors->deepAll());
}
}
$clientToken = Braintree_ClientToken::generate();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration form</title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicon and touch icons -->
<link rel="shortcut icon" href="//www.mcr-qr-time.com/img/member-1.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<style>
.img-circle {
border-radius: 50%;
}
</style>
</head>
<body>
<div class="contain">
<!-- Top menu -->
<nav class="navbar navbar-inverse navbar-no-bg" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#top-navbar-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html"><h1 class="navbar-brand">MCR Qr Time</h1></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="top-navbar-1">
<ul class="nav navbar-nav navbar-right">
<li>
<span class="li-text">
Return to homepage:
</span>
<span class="li-social">
<a href="//mcr-qr-time.com"><i class="fa fa-home"></i></a>
</span>
</li>
</ul>
</div>
</div>
</nav>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container">
<div class="row">
<br><br>
<div class="col-sm-8 col-sm-offset-2 text">
<div class="description">
<p>
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-3 form-box">
<form role="form" action="register.php(not set up yet)" method="post" class="registration-form" id="form">
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h1><strong>Registration Form</strong></h1><br>
<h3>Step 1 / 3</h3>
<p>Please fill out this form and once you have paid and confirmed your email you will be able to log in to your dashboard.</p>
</div>
<div class="form-top-right">
<img class="img-circle" src="//www.mcr-qr-time.com/img/member-1.png" width="100" height="100">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label class="sr-only" for="form-first-name">First name</label>
<input type="text" name="form-first-name" placeholder="First name..." class="form-first-name form-control" id="fname">
</div>
<div class="form-group">
<label class="sr-only" for="form-last-name">Last name</label>
<input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="sname">
</div>
<div class="form-group">
<label class="sr-only" for="form-company">Company</label>
<input type="text" name="form-company" placeholder="company" class="form-control" id="company">
</div>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 2 / 3</h3>
<p>Set up your account:</p>
</div>
<div class="form-top-right">
<i class="fa fa-key"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label class="sr-only" for="form-email">Email</label>
<input type="text" name="form-email" placeholder="Email..." class="form-email form-control" id="form-email">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="form-password" placeholder="Password..." class="form-password form-control" id="form-password">
</div>
<div class="form-group">
<label class="sr-only" for="form-repeat-password">Repeat password</label>
<input type="password" name="form-repeat-password" placeholder="Repeat password..."
class="form-repeat-password form-control" id="form-repeat-password">
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3>Step 3 / 3</h3>
<p>Subscription payment setup:</p>
</div>
<div class="form-top-right">
<i class="glyphicon glyphicon-credit-card"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label for="card-number-field">Card Number</label>
<div id="card-number-field"></div>
</div>
<div class="form-group">
<label for="security-code-field">CVV</label>
<div id="security-code-field"></div>
</div>
<div class="form-group">
<label for="expiration-date-field">Expiration Date</label>
<div id="expiration-date-field"></div>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="submit" class="btn">Sign me up!</button>
</div>
</fieldset>
</form>
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
<script src="https://js.braintreegateway.com/js/braintree-2.21.0.min.js"></script>
<script>
braintree.setup('<?php print $clientToken; ?>', 'custom', {
id: 'form',
hostedFields: {
number: {
selector: '#card-number-field',
placeholder: 'Card Number'
},
cvv: {
selector: '#security-code-field',
placeholder: 'CVV'
},
expirationDate: {
selector: '#expiration-date-field',
placeholder: 'MM/YYYY'
}
}
});
</script>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/retina-1.1.0.min.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
</html>
Upvotes: 0
Views: 1526
Reputation: 134
This may be of some use to someone, when using hosted fields or drop-in, Braintree place a hidden nonce input in the form, you just need to call it in your form handling script like below:
<?php
require_once 'braintree-php-3.9.0/lib/Braintree.php';
Braintree_Configuration::environment('production');
Braintree_Configuration::merchantId('#');
Braintree_Configuration::publicKey('#');
Braintree_Configuration::privateKey('#');
$paymentMethodNonce = $_POST['payment_method_nonce'];
$result = Braintree_Transaction::sale([
'amount' => '10.00',
'paymentMethodNonce' => $paymentMethodNonce,
'options' => [
'submitForSettlement' => True
]
]);
?>
Upvotes: 0
Reputation: 534
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact our support team.
Using Drop-in or Hosted Fields, Braintree provides you with a nonce that represents the user's payment method. This alleviates you from having to handle credit card number and expiration date information and the the PCI burden that goes along with it. Here is an example of using the nonce with Braintree_Transaction::sale
:
$result = Braintree_Transaction::sale([
'amount' => '10.00',
'paymentMethodNonce' => nonceFromTheClient,
'options' => [
'submitForSettlement' => True
]
]);
Visit the Braintree_Transaction::sale reference for more information on handling nonces.
Upvotes: 0