简体   繁体   English

PHP自定义类,PayPal API,Mailgun API,Easypost API。 他们可以一起工作吗

[英]PHP Custom Class, PayPal API, Mailgun API, Easypost API. Can they work together

I have an ecommerce site that i am building for a client. 我有一个正在为客户建立的电子商务网站。 This site had previously worked perfectly fine using procedural functions and curl to make the calls to Paypal. 该站点以前使用程序功能和curl可以很好地正常工作,可以调用Paypal。 I download the Mailgun and Easypost API manual and installed manually. 我下载了Mailgun和Easypost API手册并手动安装。 DOwn the road, I wanted to update the site to utilize PDO & OOP. 自行开发,我想更新站点以利用PDO和OOP。 I have done a fair job at getting the foundation laid. 在奠定基础方面,我做得很出色。 Now it is time to start making calls to the various API's.I installed everything using composer and currently run a dual autoloader. 现在是时候开始调用各种AP​​I了。我使用composer安装了所有内容,并且当前正在运行双自动加载器。 The composer autoload and then beneath it a custom autoload to load my classes. 作曲家会自动加载,然后在其下进行自定义自动加载以加载我的课程。 Now, when I call on the PayPal API, I get the following error: 现在,当我调用PayPal API时,出现以下错误:

Fatal error: Class 'Paypal\Rest\ApiContext' not found in /var/www/html/myla-dev/shoppingCartFinalize.php on line 18 

I think what is happening is my autoloader is trying to load this rather than the composers autoloader. 我认为正在发生的是我的自动加载器正在尝试加载此文件,而不是作曲家自动加载器。 Here is where the autoloading is occurring: 这是自动加载发生的位置:

init.php init.php

require __DIR__.'/core/functions/general.php';
function autoLoader ($class) {
  if (file_exists(__DIR__.'/core/classes/'.$class.'.php')) {
    require __DIR__.'/core/classes/'.$class.'.php';
  }
}
spl_autoload_register('autoLoader');
require __DIR__.'/vendor/autoload.php';

This file sits in project root directory and is then required at the top of every file. 该文件位于项目根目录中,然后在每个文件的顶部都需要。

File Structure 档案结构

core
--classes
----Alert.php
----....
--functions
----general.php
vendor
--composer
--easypost
--guzzle
--mailgun
--symfony
--paypal
--autoload.php
index.php
init.php
...

composer.json composer.json

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/EasyPost/easypost-php"
    }
  ],
  "require": {
    "php": ">=5.3.0",
    "easypost/easypost-php": "dev-master",
    "ext-curl": "*",
    "ext-json": "*",
    "paypal/rest-api-sdk-php":"*",
    "mailgun/mailgun-php": "dev-master"
  }
}

Any and all assistance is appreciated. 任何和所有帮助表示赞赏。 If you feel like writing code, GREAT, but that is not what I am asking for. 如果您想编写代码,那就很棒,但这不是我想要的。 That is my job, but help with reworking to make it work would be awesome. 那是我的工作,但是在返工方面的帮助会很棒。

Thanks 谢谢

It ended up being a simple syntax error. 它最终是一个简单的语法错误。 After I dumped and updated composer it still failed to work, so I just copied the code from the installation wiki. 在我转储并更新了作曲家之后,它仍然无法工作,因此我只是从安装Wiki复制了代码。 It worked so I composer their code to mine and I was missing a backslash in my call to the wiki. 它奏效了,所以我编写了他们的代码以进行挖掘,并且在我对Wiki的调用中缺少反斜杠。 Thank you for your assistance though. 谢谢您的协助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM