# Paypal

* [Как настроить Paypal ](#kak-nastroit-paypal)ссылка How to set up Paypal
* [Как создать ссылку на оплату ](#sozdanie-ssylki-na-oplatu) ссылка How to create a payment link
* [Как создать реккурентный платеж](#kak-sozdat-rekkurentnyi-platezh) ссылка How to create a recurring payment
* [Как обработать результат](#obrabotka-rezultata) ссылка  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:

<img src="https://lh4.googleusercontent.com/i7wtKw-RzPSHarXCkIVIqPvAvn_39t1r4CPL9lSmxzFc1mNiz24zHj4PJIUUhCzL-YXaNrQbK5edCP9bYHGXkIij59shZ6XPj3YZiVp4uRlDllvWRetnF1Y3GSbQXRZt03OOiGxs" alt="" width="375">

At the top, switch to Live mode and select the desired application. The settings page opens, where the data we need is located:<br>

<img src="https://lh4.googleusercontent.com/DEKr4nWXl27UVUoT4Ycl_nOx0Aj-M7KrLcgxWR-uTaUFV82416Wwd2ib4ghxQ3jiW5P53KfMwkqvB_ZS3KjLxNNdn8bzbpvVgfeV5HKsL_iFcv6bc1y_0yntseRKzwPUGz37bpnn" alt="" width="563">

Copy the data and paste it into the appropriate fields in the Mavibot settings: go to the "Acquiring" section and find the Paypal service:

<figure><img src="/files/d6r7pG9qAWrnKCWWm1eR" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/sLuHYpmmNw7vRwHVIaah" alt=""><figcaption></figcaption></figure>

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.

| Function parameters      | Parameter description                                                                                 | Note                                                                                                                                     |
| ------------------------ | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **payment\_title**       | <p>(optional variable)<br>this is the product name.</p>                                               | 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) |                                                                                                                                          |

![](https://lh4.googleusercontent.com/sVxsMZdMlVcetXrFFXEWC9lV6dNB3dzDTBWv05Cl5GiilrRWDHlAy69a_ntlX2jY3esyzOPv8TGDm-YHQwnkz1nVMlMtWL6M7rOqeJMNRs0KY22g_d50EksFL8U7y7pF2BZH6FqJ)

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 <mark style="color:red;">**Russian (ru-RU).**</mark> 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) сысылка [первоисточник](https://developer.paypal.com/api/rest/reference/locale-codes/))

You can also specify the currency in which the payment is accepted. To do this, specify the **currency** variable, the <mark style="color:red;">**ruble (RUB)**</mark> is set by default, for the dollar, set its value to USD (currency = USD). Possible currency options can be found at the link. ссылка  [ссылке](https://developer.paypal.com/docs/api/reference/currency-codes/).&#x20;

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](https://www.sandbox.paypal.com/checkoutnow?token=07N53571YM296381N)

An example of the implementation.

Setting the payment amount and the company name

<figure><img src="/files/6tc5s6qTrR7CBF5hspWo" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
&#x20;**Please note:** the **payment\_sum** variable is assigned the value last, after the optional variables **payment\_title, company\_name,** etc.
{% endhint %}

Next, specify the variable #**{paypal\_pay\_url}** in the second "Status" block:

1. The variable can be specified in the message field:

<figure><img src="/files/JCZE1bnK3TAg13yIuWKT" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/4ZA5RTkvDM6sYTdko7et" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/OftDAnUaVQkXdNstujr3" alt=""><figcaption></figcaption></figure>

When opening the payment link

<img src="https://lh3.googleusercontent.com/GvWy17AiTcE0apTWzoPjoADq9h9bXWMRjS61DC00iwnVfSojYKvGS6Puhr6Eg0KfBtBnUza1rY_Mlh0351ka2ikbmNkC6-9zjc2CP-LdUYOQjX4fMaB3V-AT9IRTrMbqRxD-KzW2" alt="" width="563">

### 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:

<table><thead><tr><th width="264">Function parameters</th><th>Parameter description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> <strong>payment_sum</strong></td><td>the required parameter is the payment amount.</td></tr><tr><td><strong>currency</strong></td><td> The default payment currency is ‘USD'. The full list is available at the link <a href="https://developer.paypal.com/docs/api/reference/currency-codes/">https://developer.paypal.com/docs/api/reference/currency-codes/</a></td></tr><tr><td><strong>payment_title</strong></td><td>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)</td></tr><tr><td><strong>payment_description</strong></td><td>short description of the payment<br>(<em>up to 127 characters</em>)</td></tr><tr><td>company_name</td><td>optional parameter, organization/company name, etc.</td></tr><tr><td><strong>locale</strong></td><td>The payment page language is specified as en-US, fr-XC, etc.<br>By default, it is ‘ru-Ru’.<br>The full list is available at the link https://developer.paypal.com/api/rest/reference/locale-codes/</td></tr></tbody></table>

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 <mark style="color:red;">**False.**</mark>

<figure><img src="/files/68GIWaB01xnBUsbTeROA" alt="" width="563"><figcaption></figcaption></figure>

`url = paypal_payment_url(2500,`` `<mark style="color:red;">`'RUB'`</mark>`, '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.&#x20;

<figure><img src="/files/YcMbGKH6gzIV7zWVIOn1" alt="" width="548"><figcaption></figcaption></figure>

<figure><img src="/files/Q02K7rNAcZC2a5R5j5dK" alt="" width="563"><figcaption></figcaption></figure>

Selecting already created offer:

<figure><img src="/files/LMrvW0QY9CpXMXZItmbZ" alt="" width="563"><figcaption></figcaption></figure>

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

<figure><img src="/files/FgdAOG2y35CoTmjPjzrN" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/1cuFRDUdlqYCDB9kyEcx" alt="" width="563"><figcaption><p>Creating a subscription offer in paypal</p></figcaption></figure>

Select the auto-debit type Fixed:

<figure><img src="/files/QDEXGnqHiniMoZjmurDH" alt="" width="563"><figcaption></figcaption></figure>

Create subscription

<figure><img src="/files/Y4FbiNKfgVabNeIxUk7R" alt="" width="563"><figcaption></figcaption></figure>

Choosing the subscription currency and debit terms:

{% hint style="danger" %} <mark style="color:red;">**Attention!!**</mark>&#x20;

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.
{% endhint %}

<figure><img src="/files/EoKAZoPwEj1EVGjEkTSL" alt="" width="563"><figcaption></figcaption></figure>

Next, activate the subscription:

<figure><img src="/files/kNwFWoPSE0F3DcIYnq2A" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/S8gz8KSviWn1fhmybn6e" alt="" width="563"><figcaption></figcaption></figure>

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

<figure><img src="/files/k9n29aIAeWaePluHu7W5" alt="" width="563"><figcaption></figcaption></figure>

The payment link is generated and returned by the function:\
**paypal\_subscription\_url(plan\_id, shipping\_currency, shipping\_payment\_sum, start\_time)**&#x20;

| Function parameters                                          | Parameter description                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">**!**</mark> **plan\_id**           | subscription plan ID                                                                                                                                                                                                                                                        |
| <mark style="color:red;">**!**</mark> **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**                                              | <p>optional parameter, date and time of the subscription start. If you do not transfer anything, then the subscription start date = the payment date.<br> Formats: %d.%m.%Y или %d.%m.%Y %H:%M. </p>                                                                        |

<figure><img src="/files/t2iypsMTvAIlVBwKfwSx" alt="" width="563"><figcaption></figcaption></figure>

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

| Function parameters          | Parameters description |
| ---------------------------- | ---------------------- |
| **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:

| Function parameters      | Description                                                                  |
| ------------------------ | ---------------------------------------------------------------------------- |
| paypal\_subscription\_id | the subscription ID that is saved to the client's variable when subscribing. |

<figure><img src="/files/2CF5AWUDQMlMAD98rbUG" alt=""><figcaption></figcaption></figure>

## How to process the result

{% hint style="info" %}
After a successful payment, callbacks will be sent to the bot, which will let you know that the payment was successful.
{% endhint %}

{% hint style="success" %}
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.
{% endhint %}

{% hint style="danger" %}
To process the callback in the block and send the user messages about the payment status, use the "Exact match" comparison type.
{% endhint %}

{% hint style="warning" %}
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.”
{% endhint %}

### 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:

<figure><img src="/files/OQQWZSyj8myZIHAqLA0M" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/Uhfb0qXskYQ35H3geFyE" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
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.
{% endhint %}

{% hint style="info" %}
More information about conditional blocks is provided in the article of the same name. [блоках с условием рассказали](broken://pages/VktePfPMzzJlbjBSqE93) ссылка
{% endhint %}

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.

{% hint style="danger" %}
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.
{% endhint %}

### For subscription payments

{% hint style="danger" %}
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.
{% endhint %}

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:

<figure><img src="/files/Jlqi8tEJjMgkQHASQMjr" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/znQg8NLZIQFlkFCcEtU4" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/payment/paypal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
