Comment on page

Integration process

Below are the classes that we will use as a basis in the CryptoPay integration and development process and what they do.

1 - We just use the Loader class to check if CryptoPay exists. If CryptoPay is not installed or active, we will prevent the errors of the plugin.

use BeycanPress\CryptoPay\Loader;

2 - The Settings class is the class we will use to access the CryptoPay settings and create new fields in the settings.

use BeycanPress\CryptoPay\Settings;
How do we access the settings?
Settins::get($key);
How to create a new setting?
Settings::createSection($options = []);
We use CSF for our settings section. You can access all fields from the link below.

3 - The class we will use to run the hooks we specified in the Filters and Actions demos.

use BeycanPress\CryptoPay\PluginHero\Hook;

4 - Helpers are not obligatory. However, as the name suggests, there are many ready-made methods in it. Simple example of these is getting the current URL and time.

use BeycanPress\CryptoPay\PluginHero\Helpers;
Classes to be used in payment process integration.

1 - The Services class includes methods that will initiate the payment process during payment integration and introduce our plugin to CryptoPay. These are the following methods.

use \BeycanPress\CryptoPay\Services;

a - registerAddon

Services::registerAddon(string $key);
This method actually just keeps records. That is, it verifies whether another plugin has received your plugin key before you do. Thus, it avoids software confusion.

b - startPaymentProcess

Services::startPaymentProcess(
array $order, string $addon, bool $confirmation = true, array $params = []
) : string
The startPaymentProcess method runs the payment process directly and activates CryptoPay's JavaScript arm, so when the page loads, you are directly greeted by the network selection screen.
What are the parameters?
  • $order => The parameter is an array and must contain 3 values. Order ID, order amount and currency. An example is given below.
    • [
      'id' => int,
      'amount' => float,
      'currency' => string,
      ]
  • $addon => We will use our add-on key, which we registered with registerAddon, in the $addon parameters.
  • $confirmation => You can specify whether to go through an approval process after the user transfers. It can be closed in processes such as donations, but it is important in payment processes.
  • $params => Parameters to be sent by the front-end to the back-end.

c - preparePaymentProcess

Services::preparePaymentProcess(
string $addon, bool $confirmation = true, array $data = []
) : string
The preparePaymentProcess method is different from the startPaymentProcess method. It does not start the payment process directly, so when the page is loaded, it is loaded blank. So how does this work for us? For example, if your order is already ready, that is, if your order amount is certain. You can start the process directly. But if there will be an amount determination process beforehand, as with our Donation plugin. You suspend the JavaScript arm using the preparePaymentProcess method. And then you start the payment process using the JavaScrtip API.
What are the parameters?
  • $addon => We will use our add-on key, which we registered with registerAddon, in the $addon parameters.
  • $confirmation => You can specify whether to go through an approval process after the user transfers. It can be closed in processes such as donations, but it is important in payment processes.
  • $data => Parameters to be sent to the JavaScript side. If you want to use parameters from front-end to back-end. You must add a value as params.
Initiating the payment process on the JavaScript API?
On the JavaScript side, you will have a variable called CryptoPay. All we have to do is start the startPayment method with an object as follows. If you do not have a confirmation process or an order ID, you can not add the i d parameter.
CryptoPay.startPayment({
id: null|int,
amount: float,
currency: string
});
If you have closed the confirmation process, that is, there will be no verification process after the transfer process. You can take action after the transfer of the user by using the callback function below. If there is a validation process, there will already be a redirection process with the result from PHP.
CryptoPay.callbacks.transactionSent = () => {
// code
}

2 - It is used to create a page that will list the transaction records specific to your add-on.

use BeycanPress\CryptoPay\Pages\TransactionPage;
What are the parameters?
  • $name => The name of the transaction page.
  • $slug => The slug of the transaction page.
  • $addon => We will use our add-on key, which we registered with registerAddon, in the $addon parameters.
  • $hooks => Each row goes through a hook loop while creating the table. Here you can add hooks with callable functions to manipulate each column value in each row.
  • $confirmation => You determine whether the transaction records on this page will enter the validation phase if there is a pending transaction while you load the page.
  • $excludedColumns => To remove columns that you do not want to show in the table.
new TransactionPage(
string $name,
string $slug,
string $addon,
array $hooks = [],
bool $confirmation = true,
array $excludeColumns = []
);

3 - If you are going to keep transaction records for your add-on, if you are doing payment process integration. You have to do this. It allows you to create a database model to keep your transaction records.

use BeycanPress\CryptoPay\Models\AbstractTransaction;
The following example is sufficient. All you have to do is use it as follows.
class DonationTransaction extends AbstractTransaction
{
public static $addon = 'donation';
public function __construct()
{
// Table name = donation_transaction
parent::__construct('donation_transaction');
}
}