0
votes

I have a web application that provides some service to customers. I want to integrate Braintree payment gateway. I have created a page which gets customer's credit card information and creates new customer in brain tree secure vault using transparent redirect method.

I have no idea what to do next to implement recurring billing. Amount to be charged from customers is different for every customer, depending on users of customers. Also billing period of each cutomer is different. I have no idea how to implement recurring billing.

Following is my code for credit card page:

<?php
require_once '../_environment.php';
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
    $queryString = $_SERVER['QUERY_STRING'];
    $result = Braintree_TransparentRedirect::confirm($queryString); 
    if ($result->success) {
       //Do your stuff
    } else {
        foreach ($result->errors->deepAll() as $error) {
            $errorFound = $error->message . "<br />";
        }
        echo $errorFound ;
        exit;
    }
}
$trData = Braintree_TransparentRedirect::createCustomerData(
  array(
    'redirectUrl' => 'https://www.example.com/creditcard.php',    
  )
);
?>

<form method="POST" action="<?php echo Braintree_TransparentRedirect::url(); ?>" autocomplete="off">
<table cellpadding="0" cellspacing="0" border="0" width="98%" align="left"> 
   <tr><td align="right" style="color:#6593cf" width="40%">Customer Information</td><td align="left" colspan="2"><hr style="color:#6593cf;margin-right:30%;margin-left:2px"></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">First Name</td><td>&nbsp;</td><td><input type="text" name="customer[first_name]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Last Name</td><td>&nbsp;</td><td><input type="text" name="customer[last_name]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Company</td><td>&nbsp;</td><td><input type="text" name="customer[company]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Email</td><td>&nbsp;</td><td><input type="text" name="customer[email]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Phone</td><td>&nbsp;</td><td><input type="text" name="customer[phone]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>                    
         <tr><td align="right" style="color:#6593cf">Payment Information</td><td align="left" colspan="2"><hr style="color:#6593cf;margin-right:30%;margin-left:2px"></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Name on Card</td><td>&nbsp;</td><td><input type="text" name="customer[credit_card][cardholder_name]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Credit Card Number</td><td>&nbsp;</td><td><input type="text" name="customer[credit_card][number]" /></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">Expiration date (mm/yy format)</td><td>&nbsp;</td><td><input type="text" name="customer[credit_card][expiration_date]" /></td></tr>   
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td align="right">CVV</td><td>&nbsp;</td><td><input type="text" name="customer[credit_card][cvv]" /></td></tr>
        <input type="hidden" name="tr_data" value="<?php echo htmlentities($trData) ?>" />
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
    <tr><td align="right"><a href=""><b>Cancel</b></a></td><td style='width:30px;'></td><td align="left"><input type="submit" value="Submit" class="btnSize" name="submit"/></td></tr>
    <tr><td colspan="3">&nbsp;</td></tr>    
</table>  

1
Hey Vishal, I work at Braintree. Have you seen our recurring billing using TR guide? It sounds like you need more help than you can get on Stack Overflow, so feel free to reach out to our support team. Also, we recommend using Braintree.js instead of TR if you're just starting your integration.agf
Thanks for replying agf. You mean I should user server-to-server api for creating customers along with Braintree.js, instead of TR?Vishal Suri
Yep. Braintree.js is now our recommended way of simplifying PCI compliance, rather than TR.agf
I have created credit card php file for saving customer information in braintree secure vault, using server-to-server api and Braintree.js. What should I do next? Should I create a plan? Should I create plan using braintree control panel or using braintree api?Vishal Suri
Did you go through our tutorials, specifically the one on recurring billing? It walks you through creating a plan and then a subscription. Also, feel free to contact our support team directly.agf

1 Answers

0
votes

You have to use braintree's specific api call for recurring billing.

Braintree_Subscription::create(array(
   'paymentMethodToken' => $payment_method_token,
   'planId' => $package_code,
   'price' => $monthly_price
));

This "Create" is for recurring billing.