omise-php
omise-php copied to clipboard
How can I add service provider
I am working on Laravel project . It throw error about the dash sign on file name 'omise-php' . How can I fix it ??
in the UsersController , you can notice that it hit the line number 6 and thrown error.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use omise\omise-php\lib\Omise;
class UsersController extends Controller
{
// ... others actions
}
in the app.php
// .. other service providers
Laravel\Cashier\CashierServiceProvider::class,
omise\omise-php\lib\Omise::class,
// .. other service providers
Error that was thrown
Moreover, in naming convention , I have never seen name with dash sign before . I have seen only camelCase , snake_case or PascalCase.
hello @khunemz
thank you for using Omise, can you give me more detail such as
- what error have you found ?
- some part of your code ?
so I can investigate your problem and give an exactly advise for you.
Hi, I also working on Laravel project using this library as well but, I don't use service provider to make this library work with laravel, instead I use this very quick and dirty way.
(I have a bad English skill, so bare with me)
- Create new folder inside 'app' directory and name it however you want.
- Put 'data', 'lib' and 'tests' folder from library in that folder.
- Create a new class and set the namespace appropriately. (Eg. App\Cashier)
- Manually include 'lib/Omise.php' into your class file, so it should look something like this.
namespace App\Services;
require_once dirname(__FILE__, 3).'/app/Omise/lib/Omise.php';
class Cashier
{
}
And just call Omise's methods inside that class like this.
namespace App\Services;
require_once dirname(__FILE__, 3).'/app/Omise/lib/Omise.php';
class Cashier
{
public static function charge(Array $data)
{
return \OmiseCharge::create($data);
}
}
Now you can use your class as an interface (not sure what to call it) to communicate with Omise from anywhere in your Laravel app. For example :
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Services\Cashier;
class User extends Authenticatable
{
/**
* Charge the customer.
*
* @param integer $amount
* @param string $card
* @return OmiseChargeObject
*/
public function charge($amount, $card)
{
return Cashier::charge([
'amount' => $amount,
'currency' => 'thb',
'customer' => $this->customerToken,
'card' => $card,
]);
}
}
And that's it.
Keep in mind that this is very quick and dirty way to do it. If you happen to find a better way, please share!
@supershooter152 useful idea , i ll try it. (could I add the 'lib' folder into autoload psr-4 ?)
@bank-omise I challenge you if you make Omise and Laravel (the world's most popular PHP framework) integrating more easily , you would solve an annoying problem in the world
Haven't got around to try it yet, but my guess is that you could.
@supershooter152 nope , it does not work . Instead it shows .
[Symfony\Component\Debug\Exception\FatalErrorException]
main(): Failed opening required '/Users/xxxxxxx/project/app/Omise/lib/Omise.php'
(include_path='.:/usr/local/php5/lib/php')
this is really quite ridiculous that you don't even namespace. you make a simple thing a big pain :-(
@jrmadsen67 Hi,
I understand. Now we are working on new version of Omise-PHP that would support namespace feature. You could follow the project here: https://github.com/omise/omise-php/projects/1#card-963281
Also, for the adding namespace PR, now it's in review process, which is you can follow the PR at https://github.com/omise/omise-php/pull/47
Cheers, Nam
It's been 2 years and you guys still haven't namespaced this? Is this ever going to happen?
Is this moving forward?
don't hold your breathe, I've been asking for namespaces for about 16 months now
We might as well fork this and add proper namespace ourselve now lol.
It would seem like the best thing to do, people have been asking for namespaces for like 3-4 years now, let alone other basic features. Seems weird that a first party package can be so outdated and unmaintained. We gave up in the end and used another payment gateway.
charge
Great