Openpay LIBRARY |
Hi! Im trying to use Openpay library in CI4 but I don't have success, I don't know if im doing right,
Im new using this framewwork, can any one help me? This is my code //controller PHP Code: <?php namespace App\Controllers; //library PHP Code: <?php namespace App\Libraries; // and content of library looks like PHP Code: <?php
What is not working? Do you have an error message?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Hi, I'm new in CI, I'm using version 4.0 and I'm dealing with the same problem, I don't know how to integrate Openpay library in order to use it as a payment gateway.
Here's where Openpay repo is for PHP: https://github.com/open-pay/openpay-php I created a folder under app/Libraries/Openpay Inside has the Openpay.php file, data and resources folders In my cart controller in app/Controllers I added the following line: use App\Libraries\Openpay; Adding this line where I need it under the controller: Openpay::setId('moiep6umtcnanql3jrxp'); I got the error that "Openpay" was not found. I also tried following the above example and still no luck. I also I added with composer : composer require openpay/sdk But I don't know how to include the autoloader Any guide/help/advice is more than welcome, thanks in advance.
Hi, while I can't guarantee this will solve your problem, in both cases above (with my limited knowledge of the subject) I can see no mention of configuring the autoload. So CI doesn't probably know where to look.
Someone please correct me if I'm wrong here but the Openpay library is not namespaced so you will have to namespace it yourself in order to use it in CI. Also, it seems there are files int here with multiple classes defined. Not sure if that's gona play nice with CI. So, once you namespace it, in app/Config/Autoload.php you need to modify the __construct function. Where the $psr4 array is defined, add something like this to the array definition: 'Openpay' => APPPATH . 'ThirdParty/Openpay' (08-26-2020, 04:44 AM)Jan Zelenka Wrote: Hi, while I can't guarantee this will solve your problem, in both cases above (with my limited knowledge of the subject) I can see no mention of configuring the autoload. So CI doesn't probably know where to look. Thanks for your quick response Jan, I will start with your suggestions.
It's hard to be sure, as there are two questions here, but I believe that with CI4 you are better off using the namespaces rather than the older method of directly loading the php files with the require_once function.
The simplest way, is to insert a USE statement at the top of the file, with the path to the library file, such as: PHP Code: use path/to/library If you are using something like VS Code, then you can have the system insert that line for you when you find an unknown class. I am not using OpenPay, so cannot give you direct help, but that should point you in the right direction.
Hi, I namespaced all the files, I moved all files to one folder and if a file has more than one class I create a separate file for the other classes in order to have 1 class per file.
I have the files in the following folder: app/Libraries/Openpay I added the following line at the top of each file under the folder Openpay PHP Code: namespace App\Libraries\Openpay; In my controller I added the following use App\Libraries\Openpay\Openpay; And in the function where I need to use it I added the following: Openpay::setId('mysecretid'); Openpay::setApiKey('mysecretkey'); The problem that I have now it's when I call any of the class/method like: $customer = $openpay->customers->add($customerData); $charge = $openpay->charges->create($chargeData); I get the following error: Call to undefined method stdClass::create() Call to undefined method stdClass::add() I don't know why I'm getting this error and how to fix it. Do you have an idea what I'm doing wrong or what I need to change? Thanks for your help. (08-30-2020, 02:34 PM)cgowez Wrote: The problem that I have now it's when I call any of the class/method like:Looks like the $openpay variable is not initialized to an openpay class. Have you created the $openpay object? From the docs: PHP Code: $openpay = Openpay::getInstance('MERCHANT_ID', 'PRIVATE_KEY', 'COUNTRY_CODE');
I tried both options:
Openpay:etId('moiep6umtcnanql3jrxp'); Openpay:etApiKey('sk_3433941e467c4875b178ce26348b0fac'); Or $openpay = Openpay::getInstance('MERCHANT_ID', 'PRIVATE_KEY', 'COUNTRY_CODE'); With same result. |
Welcome Guest, Not a member yet? Register Sign In |