0

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>  

halfer
  • 19,824
  • 17
  • 99
  • 186
Vishal Suri
  • 447
  • 2
  • 12
  • 32
  • Hey Vishal, I work at Braintree. Have you seen our [recurring billing using TR guide](https://www.braintreepayments.com/docs/php/guide/recurring_billing_with_tr)? It sounds like you need more help than you can get on Stack Overflow, so feel free to reach out to our [support team](https://www.braintreepayments.com/support). Also, we recommend using [Braintree.js](https://www.braintreepayments.com/docs/javascript) instead of TR if you're just starting your integration. – agf Jun 05 '13 at 22:47
  • 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 Jun 06 '13 at 04:56
  • Yep. Braintree.js is now our recommended way of simplifying PCI compliance, rather than TR. – agf Jun 06 '13 at 05:06
  • 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 Jun 06 '13 at 11:28
  • Did you go through [our tutorials](https://www.braintreepayments.com/docs/ruby/guide/overview), specifically the one on [recurring billing](https://www.braintreepayments.com/docs/ruby/guide/recurring_billing)? It walks you through creating a plan and then a subscription. Also, feel free to contact our [support team](https://www.braintreepayments.com/support) directly. – agf Jun 06 '13 at 12:55
  • I have created a plan in braintree sandbox account. I am reading recurrring billing tutorial and it says: “In your app.rb file, replace the post '/create_customer' route to pass along the Customer ID:” But I do not have any app.rb file. I have a simple creditcard.php file which creates customers in braintree secure vault using server-to-server api and braintree.js. I have also send email to braintree support regarding this. – Vishal Suri Jun 07 '13 at 06:16
  • @VishalSuri, have you find a solution for above question ? If you found please share with me. – Ulug'bek Jun 23 '15 at 10:04

1 Answers1

0

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.

rafi
  • 1,493
  • 3
  • 31
  • 43