Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Torger Angeltveit
Torger Angeltveit
11,228 Points

Integrate payment gateway with PHP

Hi, i've seen the treehouse videos on how to integrate paypal with PHP and it's pretty simple and straight forward.

I was wondering if treehouse have any vids on how to do it with credit card gateways?

Is the way you integrate credit card gateway with PHP the same concept as when you do it with paypal? Or is it a huge differences

Ron McCranie
Ron McCranie
7,837 Points

I think it depends on what you're considering a "credit card gateway"? Could you provide a specific example? Just checking to see if you mean integrating a hardware device or a web service.

4 Answers

In my opinion, Stripe is the best credit card gateway API. It's incredibly easy and can be used with multiple languages. TeamTreeHouse has a tutorial for PHP over here https://teamtreehouse.com/library/php-the-stripe-api. If you have any questions about Stripe, I'll gladly answer them.

Also, what I like the most about Stripe is the ability to go into development mode so you can test your payments with test credit cards.

Torger Angeltveit
Torger Angeltveit
11,228 Points

Thank you! exactly what i was looking for! :)

Torger Angeltveit
Torger Angeltveit
11,228 Points

I've watched the stripe tutorial. But i dont understand how i asign the button to a spesific product in my array? Instead of just asigning the button to a static item?

basically how / where do i asign the payment to a spesific item ID ? Do i have to asign every product in my array witha different publishable_key?

Check out their API over at this website: https://stripe.com/docs/api

The method I suggest looking under is the create a charge method.

Below is an example PHP API request:

\Stripe\Stripe::setApiKey("sk_test_83osNQbFfgsGDSFsdfgMNL9C4mt");

\Stripe\Charge::create(array(
  "amount" => 400,
  "currency" => "usd",
  "source" => "tok_163tberhWssfFDewfjkljljfhnfgfIiUPXW", // obtained with Stripe.js
  "description" => "Charge for test@example.com"
), array(
  "idempotency_key" => "x7SI7efhfsdgfXSttQu",
));
Torger Angeltveit
Torger Angeltveit
11,228 Points

I mean asigning a checkout to a e-commerce so you can pay with credit card directly by asigning your credit card information into a form

Ron McCranie
Ron McCranie
7,837 Points

I don't think there's any treehouse videos specifically about other processing services. Taking what is taught in the PayPal integration course, you could read over the documentation of another service. Sounds like you're wanting to integrate something like Stripe