Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

How do have two stripe payment buttons

How would I go about adding two stripe payment buttons on one form? Is this possible. I already have one payment button setup and it is working.

However now I want to add another one but it is not working I get the error;

Fatal error: Uncaught Error: Call to undefined function Stripe\HttpClient\curl_init() in /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php:80 Stack trace: #0 /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/ApiRequestor.php(178): Stripe\HttpClient\CurlClient->request('post', 'https://api.str...', Array, Array, false) #1 /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/ApiRequestor.php(59): Stripe\ApiRequestor->_requestRaw('post', '/v1/charges', Array, Array) #2 /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/ApiResource.php(108): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array) #3 /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/ApiResource.php(148): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL) #4 /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/Charge.php(37): Stripe\ApiResource::_create(Array, NULL) #5 /var/www/html/southlondontutors.com/index.php(426): Stri in /var/www/html/southlondontutors.com/vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php on line 80

the forms I have used on my booking page are;

{% if not is_user_logged_in %}
    <a class="group-tutors" href="/login">Login</a>
{% elseif group.booked %}
    Booked
    <form action="/charge1" method="post">
        <script
            src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="pk_test_7WJNkl33Jt9eXmBD7aujJniy"
            data-image="images/footer-icon.png"
            data-name="SOUTH LONDON TUTORS"
            data-description="Lift"
            data-amount="500"
            data-currency="GBP"
            data-locale="auto">
        </script>
        <input type="hidden" name="tutoremail" value="{{ group.tutoremail }}"/>
    </form>
{% elseif group.available > 0 %}
    <form action="/charge" method="post">
        <script
            src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="pk_test_7WJNkl33Jt9eXmBD7aujJniy"
            data-image="images/footer-icon.png"
            data-name="SOUTH LONDON TUTORS"
            data-description="{{ group.topic }}"
            data-amount="2000"
            data-currency="GBP"
            data-locale="auto">
        </script>
        <input type="hidden" name="tutoremail" value="{{ group.tutoremail }}"/>
        <input type="hidden" name="starttime" value="{{ group.starttime }}"/>
        <input type="hidden" name="description" value="{{ group.topic }}"/>
    </form>
{% else %}
    Full
{% endif %}

and on my index.php (controller) I have

$app->post('/charge', function(Request $request) use($app) {
    $description = $app['request']->get('description');
    $tutoremail = $app['request']->get('tutoremail');
    $starttime = $app['request']->get('starttime');
    $user = $app['auth']->get_user();
    $studentemail = $user['email'];

    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_fktchFYkd0XywraJftt8Z9uc");

    // Get the credit card details submitted by the form
    $token = $app['request']->get('stripeToken');

    // Create the charge on Stripe's servers - this will charge the user's card
    try {
        $charge = \Stripe\Charge::create(array(
            "amount" => 2000, // amount in cents, again
            "currency" => "gbp",
            "source" => $token,
            "description" => $description . ' paid by ' . $studentemail . ' for session ' . $tutoremail . '/' . $starttime
        ));
        $app['tutor']->add_group_tuition_booking($tutoremail, $starttime, $studentemail);
    } catch(\Stripe\Error\Card $e) {
        // The card has been declined
    }
    return $app->redirect('/group-tuition');
});

$app->post('/charge1', function(Request $request) use($app) {
    $description = $app['request']->get('description');
    $tutoremail = $app['request']->get('tutoremail');
    $user = $app['auth']->get_user();
    $studentemail = $user['email'];

    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_fktchFYkd0XywraJftt8Z9uc");

    // Get the credit card details submitted by the form
    $token = $app['request']->get('stripeToken');

    // Create the charge on Stripe's servers - this will charge the user's card
    try {
        $charge = \Stripe\Charge::create(array(
            "amount" => 500, // amount in cents, again
            "currency" => "gbp",
            "source" => $token,
            "description" => $description . ' paid by ' . $studentemail . ' for lift to session by ' . $tutoremail
        ));
    } catch(\Stripe\Error\Card $e) {
        // The card has been declined
    }
    return $app->redirect('/group-tuition');
});