CakePHP - Klarna API - Installing & running an external app PHP API - php

I think this question relates to most PHP API's you download and run in your application. I want to integrate the Klarna API with my CakePHP application. Now, I am not a very seasoned CakePHP programmer so my questions might be very rudimentary. But I haven't figured this out conceptually, how it works with external non-CakePHP software in a CakePHP app. Basically how do I set it up and use it.
In which folder do I put the Klarna files in my CakePHP app? Webroot?
To initialise and configure the Klarna API for use, do I simply put the Klarna code in the controller without messing about with any of the CakePHP component / plugin load procedures?
Do I then run the API code in the controller as well?
I don't need to be using cURL to talk to Klarna in this case right? The Klarna API will make the call to Klarna's servers itself?

Provided you have received testing login credentials from Klarna, this is a working example:
Download the PHP API from Klarna. The files should be placed in the "/Vendors" folder as per
Loading Vendor Files in CakePHP 2.0
& App Class, I put them in a folder named "klarna" for the sake
of organising things. Klarna API consists of quite a few files so
can be a good idea.
You'll initialise and setup the API in the relevant
controller, or I did at least. To load the vendor files do:
App::import('Vendors, 'klarna/klarna');. Given CakePHP's folder structure, I had to modify a couple of lines from the .getAddresses file example. One was previously '/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc', became '/vendors/klarna/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc'. Similar for the one two lines below. Remember to set the test-accounts "Shared secret" and "merchant ID" as well as having the right test-server configured. Then you can test the API against one of Klarna's test persons.
Yes, the configuration and execution of the Klarna API both happens
in the controller as per examples. It's just normal PHP code though.
We don't need to be using cURL for this API. The API takes care of the calls itself.

Related

Call Symfony API Platform custom filters from within the application

I have built custom filters on API Platform w/ Symfony. I'm writing a command that needs to use these filters. I think making an API call from within the application isn't a clean way to do it and duplicating the functionality by writing query builders seems dumb.
Anyone know how to grab the data from within the Symfony application i.e. from a command or a controller?
Obviously I could just hit the endpoint, and this works fine, but it seems wrong to get data into one part of the app from another via an HTTP call.

Upgrade Monolithic Laravel Application to Microservices

I am a newbie in microservices and done my research on the best practices and how to upgrade from monolithic. I need now concrete steps to move forward.
I am looking to upgrade a monolithic Laravel project to Microservices.
I have started to break the app into smaller apps. So developed multiple Laravel projects each representing a service. To simplify the question:
Authentication app: used for user authentication and registration
ToDo app: used to create a todo-list with tasks for a specific user
So now I have these two apps where each has its own CRUD operations (multiple APIs).
The question is how to move these apps to AWS serverless using Lambda Functions, API Gateways and Connect to PostgreSQL (Aurora DB).
First I need either to use the SAM template or the Bref template? And how to handle that AWS Lamda does not support Laravel?
Each app has several functions in it (the first app has signup, login, reset password...) so does each one of these must be an independent Lambda function? If yes does this mean each has to be a new Laravel project and then I will have to mention the same resource to be used by SAM or Bref to have the different functions to use the same DB.
Lambda creates by default an API Gateway? If yes then shall I create a main API gateway accessible by the user-side which can call the other API gateways? (Main API Gateways filters the request and if related to authentication it redirects to Authentication Gateway that can interact with the different Authentication Lambda functions?
I Will later have definitely to add step functions with SNS queuing support but for now, I need to understand how to move the apps.
And finally, how would you recommend integrating CI/CD into the project?
Thanks for the help!
You can follow the instructions on the Bref documentation, installing both packages.
composer require bref/bref bref/laravel-bridge --update-with-dependencies
To answer your second question, it is your own choice if you want to break it down to smaller individual lambda function, or use the entire app as a function. Both can work. You may also include multiple functions per application and use an API Gateway to route specific request to the respective lambda. If you decide do just have one function, then all requests just have to be routed to the same lambda. It's your choice.
Lambda doesn't create the API gateway by default, the serverless framework does it for you if you include the following lines in your serverless.yaml file.
events:
- httpApi: '*'
I would suggest you stick with one API gateway for a simpler routing configurations. You can configure the API Gateway to route different requests to different services.
Finally you can implement CI/CD with a pipeline, using a Git repo as a trigger and configure CodeBuild to deploy your app to Lambda.

Port a nextjs application into a php site

I have a nextjs app that I'm using to process stripe payments that I've deployed to Vercel. The app is simply a form with tons of functionality built in but requires the use of an api (which is why I'm using nextjs). What is the best way to get this into a php site? I need to access the nextjs api in order to communicate with stripe. Otherwise I would have just built the react app in the php site and rendered it on the page in question per usual. I've never done this before, so please any recommendations would be huge.
Here are the options I've come up with:
iframe. I've never been a huge fan of these, but figured this was an option. I can render my app via iframe on the php site.
use the vercel deployed nextjs app strictly for the api and build the react form into the php site. Then I would simply change the api requests to point to the vercel deployed nextjs app instead of a local api.
Are there better more efficient methods?
Try vercel-php, a PHP runtime for Vercel. Using the configuration described in the README, you can use a PHP repository as your backend and fetch data from there for your NextJS app.
Alternatively, you can use this directly in your NextJS repository and instead of having the api folder inside the pages directory, just have it as a top-level directory

Best approach for creating API for web, android, iOS application

I am working in a project which will have a web, android and iOS application.I have decided using laravel 5.4 to create the web application and also there will the rest api to feed all these app. The api should also be secured so that only my app can access them.
Anyone please tell me from your previous experience what will be the correct way and the best practice to do this
You can use Node.js or Python on which you can develop rest API very easily.The framework like express in Node.js and Flask in python will let you get started with your API within 30 min.After that, you can deploy the API to Heroku to get secure access
If the web, android and IOS application relate to the same project / resources (e.g. database tables, etc.), the easiest way to do this would be a single Laravel project.
In your routes directory, you can have 3 different files (say web.php, ios.php and android.php) to define the routes. Similarly, you can place controllers in separate directories while keeping the Eloquent models/migrations, etc. the same for all three.
To use different authentication methods for all three, you can add custom guards in Laravel.
I would not build anything in larvel and run away form php as soon as possible. Go learn node.js or django. Death to php.
The best current framework to builds apis is Sanic.
Sanic 33,342 Requests/sec 2.96ms Avg Latency
https://github.com/channelcat/sanic
I also like python flask because it is very simple to understand and get something up and running quickly.
Your app currently does not need to be super optimal all you need to is getting working, But best practice wise i think the most important thing for building apis for mobile apps is backwards compatibility.
Sometimes your going to want to update the your app.
Users often don't update the apps. So if you build a new api all the people who dont update their app will get error messages. So just make sure you make a new route with the version name in the prefix in the app. There is alot of other things you can do like rate limiting,Salting your apis and ect. If you dont have that many users don't worry about this yet. Just build it and then latter learn when you need to learn in.

How do CI server work without manually having to set up webhooks?

I am curious as how to CI servers like Jenkins and CI travis manage to watch for push events or changes at least to launch their build pipelines. So far what I have seen when you want to create your own server you have to set up webhooks that push data to an API endpoint.
Do CI servers like Jenkins and Travis automatically add webhooks to github or something or do they work differently? I would love to set up a really small PHP specific CI server but obviously I don't want people to have the hassle of setting up a webhook every time they add a repo. Simply adding your repo should suffice. Optionally logging in with a Github account.
Edit
I don't see why this is getting downvoted. I would love if somebody could go a little bit more in depth on how a hook works that is not set up through github's webhook interface.
CI systems usually comes with hooks that are already part of the system (or easy to install).
Specifically in jenkins there is a GitHub plugin that gives you the ability to:
Create hyperlinks between your Jenkins projects and GitHub
Trigger a job when you push to the repository by groking HTTP POSTs from post-receive hook and optionally auto-managing the hook setup.
Report build status result back to github as Commit Status (documented on SO)
(And probably more).
And plugin/ci system has it's own triggers/hooks for different workflows.

Categories