Paypal
Как настроить Paypal ссылка How to set up Paypal
Как создать ссылку на оплату ссылка How to create a payment link
Как создать реккурентный платеж ссылка How to create a recurring payment
Как обработать результат ссылка How to process the result
How to set up Paypal
To work with Paypal, you need to get two keys: client_id and secret
Go to the page https://developer.paypal.com/developer/applications/
And choose from the list or create a new application:
At the top, switch to Live mode and select the desired application. The settings page opens, where the data we need is located:
Copy the data and paste it into the appropriate fields in the Mavibot settings: go to the "Acquiring" section and find the Paypal service:

Next, click "Connect" and fill in the fields with the previously received secret key and Client ID:

Next, click "Save settings". This completes the connection.
How to create a payment link
Using payment_sum variable
To generate a payment link, you need to set the value of the payment_sum variable and immediately after that the paypal_pay_url variable will appear.
payment_title
(optional variable) this is the product name.
If it's not specified, it is filled in with the text: “Invoice payment order_id" (order_id is the order identifier in the mavibot)
payment_description
product description, optional field
company_name
the name of your company is displayed at the very top of the payment page (example is below, company)
In addition, before specifying the payment_sum, you can specify which language the payment page will be in.
To do this, set the locale variable. The default language is Russian (ru-RU). Possible options: da-DK, he-IL, id-ID, ja-JP, no-NO, pt-BR, ru-RU, sv-SE, th-TH, zh-CN, zh-HK, zh-TW, etc.(the set of available languages varies, focus on the original source) сысылка первоисточник)
You can also specify the currency in which the payment is accepted. To do this, specify the currency variable, the ruble (RUB) is set by default, for the dollar, set its value to USD (currency = USD). Possible currency options can be found at the link. ссылка ссылке.
And the third additional parameter is company_name - the name of your company, displayed at the very top of the payment page (example is below, company )
The paypal_pay_url variable can be displayed with a link or placed on a button with the text "Pay".
The link looks like: https://www.paypal.com/checkoutnow?token=07N53571YM296381N
An example of the implementation.
Setting the payment amount and the company name

Please note: the payment_sum variable is assigned the value last, after the optional variables payment_title, company_name, etc.
Next, specify the variable #{paypal_pay_url} in the second "Status" block:
The variable can be specified in the message field:

The variable can be specified in the url field in the attachment settings:

The variable can be specified in the url field in the button settings:

When opening the payment link
Using the calculator function paypal_payment_url
Create a funnel constructor block and use the paypal_payment_url function in the calculator, passing the necessary parameters to it:
! payment_sum
the required parameter is the payment amount.
currency
The default payment currency is ‘USD'. The full list is available at the link https://developer.paypal.com/docs/api/reference/currency-codes/
payment_title
the payment header (up to 127 characters). (If omitted, it is filled in with the text: “Invoice payment payment_id”, where payment_id is the order ID in Mavibot)
payment_description
short description of the payment (up to 127 characters)
company_name
optional parameter, organization/company name, etc.
locale
The payment page language is specified as en-US, fr-XC, etc. By default, it is ‘ru-Ru’. The full list is available at the link https://developer.paypal.com/api/rest/reference/locale-codes/
When the block condition is met, the client will receive a payment link, and the paypal_payment_completed client variable will be created with the value False.

url = paypal_payment_url(2500, 'RUB', 'Invoice payment payment_id','payment description', 'organization name', 'ru-Ru')
How to create a recurring payment
To create and receive a link to pay with recurring payments, you need to create a subscription plan in your personal account.


Selecting already created offer:

Alternatively, type the offer name into the search bar and click "Create".


Select the auto-debit type Fixed:

Create subscription

Choosing the subscription currency and debit terms:
Attention!!
In Mavibot, the default currency is in euros, if the debit is in dollars or in another currency, then when creating a subscription, specify the currency you need and in Mavibot the same currency from the Paypal subscription.

Next, activate the subscription:


After creation, its ID will be available, which we will use in the future to create a subscription and receive a payment link.

The payment link is generated and returned by the function: paypal_subscription_url(plan_id, shipping_currency, shipping_payment_sum, start_time)
! plan_id
subscription plan ID
! shipping_currency
if the payment for the specified plan is in dollars, then you don't have to transfer anything, otherwise we transfer the currency code that you specified in the plan. The currency in which the delivery is paid is transmitted here (even for zero cost). By default, USD
shipping_payment_sum
This is an optional parameter that specifies the delivery cost. By default, the value is set to zero.
start_time
optional parameter, date and time of the subscription start. If you do not transfer anything, then the subscription start date = the payment date. Formats: %d.%m.%Y или %d.%m.%Y %H:%M.

When creating the link, the paypal_subscription_id variable will also appear, which will contain the subscription ID.
During payment, you will receive a callback, which is similar to paying for a regular payment.
paypal_subscription_data(paypal_subscription_id) - getting information about subscription
paypal_subscription_id
the subscription ID.
The result of executing the function - is an array containing all information about the subscription, including the number of payments, the number of failed charge attempts, the status, and more.
How to cancel subcription
paypal_remove_subscription(paypal_subscription_id) function will help clients cancel their subscriptions to your services.
Parameters:
paypal_subscription_id
the subscription ID that is saved to the client's variable when subscribing.

How to process the result
After a successful payment, callbacks will be sent to the bot, which will let you know that the payment was successful.
In the system, you see callbacks as messages from the user, but the user himself DOES NOT SEE them: they are displayed only to the operator.
To process the callback in the block and send the user messages about the payment status, use the "Exact match" comparison type.
Callbacks may be delayed, so after displaying the payment link to the user, it is recommended to send a message such as: “After making the payment, please wait for a confirmation message indicating that the payment was successful.”
For direct payment
The successful payment callback consists of the first 10 characters of the secret and the signature with the status. For example: EHsWHYOoWV_success
Example 1: reaction to a successful payment using the "Start condition" block:

Example 2: reaction to a successful payment using the "Start condition" block:

If you don’t want to take the user out of the main chatbot flow, use the “No-state with condition” block — users can’t be redirected to this block directly, so after a successful payment they will still remain in the main funnel, while also receiving a notification about the successful payment.
But if you do want to continue the funnel based on the successful payment event, use the “Start condition” block. In this case, after completing the payment block, the user will be redirected to the “Start condition” block, from which you can continue building your funnel.
More information about conditional blocks is provided in the article of the same name. блоках с условием рассказали ссылка
Upon successful payment, the paypal_payment_completed variable is set to True.
After the payment is completed, the paypal_callback_data variable is added to the client, which contains up-to-date payment system data on the transaction status. You can extract the necessary data from the received dictionary using the get method.
To make a repeat payment, you need to reset the payment_sum variable, the variable with the previously generated link, and then reassign the payment_sum variable or call the function to get a new link.
For subscription payments
The callback setting function for subscription-related operations was added on 09/01/2024. For the callbacks of this category to work correctly, you need to disable and connect integration of the Paypal payment system in your project.
When making a subscription payment, the bot will receive one of the following messages:
about subscription activation. For example, subscription_I-PTV5H4MRC1H3_activated;
Notification of a successful recurring subscription payment. For example, subscription_I-PTV5H4MRC1H3_paid;
or about a subscription payment error. For example, subscription_I-PTV5H4MRC1H3_not_paid;
In the examples above “I-PTV5H4MRC1H3” -is the ID of the client's subscription, which can be accessed using paypal_subscription_id variavle.
The callback will add the paypal_subscription_callback_data variable to the client, which contains current payment system data on the transaction status. You can extract the necessary data from the received dictionary using the get method.
Example 1: reaction to subscription activation using the "Start condition" block:

Example 1: Reaction to subscription activation using the "Not state with condition" block:

Last updated