BESTFY Pagamentos (Payment) Gateway Integration in PHP

BESTFY Pagamentos (Payment) Gateway Integration in PHP

BESTFY Pagamentos (Payment) is a Brazilian payment gateway that allows merchants to accept payments using a variety of methods, including Pix, Boleto, and credit cards. In this tutorial, we will walk you through the procedures of integrating the BESTFY Pagamentos gateway into your PHP application.

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

BESTFY Pagamentos Gateway Integration

Before we begin, please ensure you have the following:

  • BESTFY’s API credentials: To authenticate your requests, you’ll need the API key provided by BESTFY.
  • PHP Environment: Make sure you have PHP 7.2 or higher installed.
  • Composer: We’ll use Composer to install the Guzzle HTTP client, which will handle API requests.

1. Setting up the BESTFY API with Guzzle HTTP

BESTFY provides a REST API for creating transactions, handling payments, and receiving postback notifications. To make HTTP requests from PHP, we will use Guzzle, a popular PHP HTTP client.

Install Guzzle via Composer

If you haven’t already installed Guzzle, run the following command:

This will install Guzzle and all necessary dependencies.

Suggested Read: Authorize.Net Payment Gateway Integration using PHP

Initialize Guzzle Client for BESTFY

Next, set up a Guzzle client in your PHP script to interact with the BESTFY API. Here’s how you can configure it:

You can now use this client to make API requests.

2. Creating a Transaction in BESTFY

To accept payments through BESTFY, the first step is to create a transaction or checkout session. This will generate a payment URL that you can redirect the user to for completing the payment.

API Request to Create a Transaction

Here’s how you can make a POST request to the BESTFY API to create a transaction:

In this code:

  • Replace YOUR_API_KEY with your actual BESTFY API key.
  • The amount field represents the total amount in cents (for example, 10000 cents = R$100.00).
  • postbackUrl is where BESTFY will send the payment status after processing. We’ll handle this later.

Once the request is successful, BESTFY will return a checkoutUrl that you can redirect the user to for completing the payment.

Also Read: How to Integrate Paypal Payment System with Paypal API in PHP and MySql

Redirect User to BESTFY Checkout Page

After receiving the checkoutUrl, you can redirect the user to that URL for payment:

3. Handling Postback and Order Status Updates

BESTFY will notify your server about the payment status via a postback request to the postbackUrl you specified when creating the transaction.

Handling the Postback Request

Create a script at the postback URL (e.g., postback.php) to handle the postback data. BESTFY will send a JSON payload with the transaction details and payment status.

Here’s how to handle the postback:

To store transaction information, such as the transaction ID and payment status, you can save it in your database using PHP’s database interaction functions.

Do you want to get implementation help, or modify or extend the functionality of this script? Submit a paid service request

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

Conclusion

Integrating BESTFY Payment into your PHP application provides a seamless way to accept payments through various methods, including Pix, Boleto, and credit cards. By using Guzzle to communicate with the BESTFY API, you can easily create transactions, redirect users to secure payment pages, and handle postback notifications to update order statuses in real-time.

This integration enhances your checkout process, offering customers a smooth and secure experience. With careful implementation and testing, you can confidently provide a reliable payment solution that meets the needs of your business and customers alike.

Recommended Article: Integrate Recurring Stripe Subscription Payment with PHP

FAQs

What is BESTFY Payment Gateway?

BESTFY Payment Gateway is a Brazilian payment solution that enables merchants to accept payments through various methods, including Pix, Boleto, and credit cards. It provides a secure way to process transactions and offers multiple integration options for e-commerce websites and applications.

What are the payment methods supported by BESTFY?

BESTFY supports multiple payment methods, including:
1. Pix (instant payment)
2. Boleto Bancário
3. Credit Cards

Is the BESTFY payment page secure for customers?

Yes, BESTFY provides a secure, SSL-encrypted payment page that customers are redirected to for completing their payments. This ensures that all payment information is transmitted securely.

Can I customize the payment experience for customers?

BESTFY allows some level of customization, such as selecting which payment methods to offer (Pix, Boleto, credit card) and setting default payment methods. However, the checkout process itself is hosted by BESTFY, ensuring security and compliance with payment regulations.

Related posts

Leave a Comment