M
M
maclaud7772014-03-22 23:01:12
API
maclaud777, 2014-03-22 23:01:12

First API server on Kohana - where to start?

Task:
Implement a payment gateway for various payment systems (in particular, for Yandex.Money and WebMoney so far). Payments must go through the gateway, data about them is stored in the database, and a response is sent to the application about the result of the payment. Subsequently, other projects will use this gateway.
In general, you should get something like your own little robokassa or interkassa: an API for working with another API.
I can't think clearly about the architecture of the future API server. I was looking for at least some material, everywhere it is described how, for example, to write a RESTful API application (server), that is, how to organize communication between the server and the client. But nowhere are there examples or manuals on how to write classes correctly, the methods themselves, how to determine which method to call on request taking into account the use of the mvc pattern, but not the point). It should be borne in mind that in the future it will be necessary to implement support for ever larger payment systems.
Can someone share their experience, or suggest a competent resource/material for in-depth study?
PS In PHP, and in programming in general, I am far from being a pro, I have not written large projects much, therefore, maybe I did not explain the problem quite clearly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
ZoorGan, 2014-03-23
@ZoorGan

I will give a small example of the most primitive implementation.
Routing:
Controller:

class Controller_User extends Controller {

  public function action_get_by_id()
  {
                $user_id = $this->request->post('user_id');
                $user = DB::select()->from('users')->where('id','=',$user_id)->execute();
    $this->response->body(json_encode($user));
  }
}

We simply sent a json string as a response to a POST request to the address: site.ru/user/get_by_id. In the POST request, we sent the user_id variable, which we processed and accepted in the desired action. This code is not a standard, but I think the principle is clear. You are required to write a base controller for all apish controllers and take into account header handling, unify responses to requests, etc. Take
a look at this module as an example: https://github.com/samkeen/kohana-simple-REST . It is quite simple and, from my point of view, convenient, although I would remove the work with the database in it.

M
maclaud777, 2014-03-24
@maclaud777

See if you can make it easier. I probably didn't formulate the question correctly. But the problem has already almost solved itself. Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question