O
O
Orc2017-04-29 06:23:46
PHP
Orc, 2017-04-29 06:23:46

How to implement an automatic transfer from a replenished transaction from the main wallet to others minus a percentage of the amount?

We are developing a service for accepting charitable payments. I chose Yandex. Money. The task was to transfer from the general internal account to the accounts of the participants their accumulated fees. I made the opposite decision in order not to bother with reporting - not to accumulate the fee and transfer it as a result in one amount, but to conduct end-to-end donation transactions immediately to the target wallets of the participants, minus interest for payment on the main wallet of the system. I read the Yandex.Money API, figured out how to get a token - got it. We need the help of an initiate who has already passed this path. My friends, can share the design of the code, maybe someone has already written something like this . Do a good deed.
Thank you!..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
ozornick, 2017-04-29
@ozornick

Let's say the commission is 10%. There are 1000 rubles on the account. You need to transfer 100 rubles. addressee. Accordingly, before creating a payment, we calculate the amount of the transfer.
$amount = 100 - (100 * 0.1) // 90
Now you transfer 90 rubles. and 10 rubles. commission remains in the system. Did I understand correctly?

O
Orc, 2017-04-29
@z0ddak

ozornick , thanks for responding...
Yes, it's not a problem to calculate... Moreover, I can do it using the CRM system. I have all the calculation for the participants in CRM, and the handler only snatches the necessary fields during requests ...
The complexity is in the code design itself, I can’t figure out how to write it. On this occasion, you will not find anything in the public - I rummaged through everything. I would like to solve both the deduction of interest and the transfer ON THE SIDE of the wallet with one request to the Yandex API.
Let's say now I see it like this:
- the donator transfers the amount to the main wallet of the service through a form tied to a specific participant in the system for which this fee passes;
-when submitting the form, a record is created in CRM about the donator and all information about the transaction + the necessary fields are automatically calculated (the amount to be paid to the wallet of the participant from whose form the donation was received, minus the percentage) + funds are transferred to the main wallet of the service;
- Yandex responds with a 200 OK http request , launches a handler that generates a request to the API to transfer funds to the participant.
- Yandex sends 200 OK again , confirming the success of the transfer and returning some information...
So it is clear that at least two requests are needed - the first one is to replenish the account, and in the second one the amount for the transfer minus the percentage and the target wallet of the participant flies. I consider this construction redundant and everything can be solved on the Yandex side with one request immediately from the form. Well, she haunts me) I'm sure that someone has already DECIDED and READY to share with the public.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question