【问题标题】:How to configure CreditCard class in Omnipay?如何在 Omnipay 中配置 CreditCard 类?
【发布时间】:2015-08-05 02:37:45
【问题描述】:

我整天都在尝试在 CodeIgniter 中配置 Omnipay,我想我终于破解了它,但我卡在了信用卡验证部分。出于某种原因,当我运行我的时,我收到错误消息Fatal error: Class 'CreditCard' not found in C:\xampp\htdocs\trabajo\emarket\application\controllers\inicio.php on line 37

这是我的控制器:

use Omnipay\Omnipay;

class Inicio extends CI_Controller {

public function index()
{
    $gateway = Omnipay::create('PayPal_Pro');

    $gateway->setUsername('######');
    $gateway->setPassword('######');
    $gateway->setSignature('#####');
    $gateway->setTestMode(true);

    $gateway->initialize();

    $cardInput = array(
        'firstName' => 'buyer',
        'lastName' => 'one million',
        'number' => '4032031186341789',
        'company' => 'Visa',
        'billingAddress1' => 'bill me here',
        'billingAddress2' => 'or maybe here',
        'billingPhone' => '4085873015',
        'billingCity' => 'chicago',
        'billingState' => 'illinois',
        'billingPostCode' => '646960',
        'shippingAddress1' => 'ship it here',
        'shippingAddress2' => 'or ship here',
        'shippingPhone' => '98789987',
        'shippingCity' => 'chicago',
        'shippingState' => 'illinois',
        'shippingPostCode' => '989898',
    );

    $card = new CreditCard($cardInput);
}
}

感谢您抽出宝贵时间,非常感谢您对我做错的地方提出一些建议。

【问题讨论】:

  • 尝试添加use Omnipay\Common\CreditCard
  • @Tpojka 非常感谢,解决了!这是否意味着每次我想调用一个类时,我都必须以这种方式将它添加到我正在处理的每个文件中?
  • 通常是的。我假设您正在使用作曲家,并且某些软件包具有自动加载文件,您应该将其包括在内,以防对所有类进行处理。检查this answer
  • 请写评论作为答案,我会接受 :) 是的,我从 index.php 调用自动加载文件这就是为什么我认为我不需要添加每个类分别地。这不是很方便,是吗?
  • “公司”字段是购买者代表的公司,而不是发卡机构。别忘了还需要设置国家/地区(美国),州需要是两个字符的代码(IL)。

标签: codeigniter paypal-sandbox omnipay


【解决方案1】:

类已加载,但您需要指向它们。而您正在使用关键字use 来执行此操作。否则你可以通过类似的东西:

$gateway = Omnipay\Omnipay::create('PayPal_Pro');//not quite sure if you need backslash infront of vendor name

或者您可以调用 CreditCard 实例的相同方式:

$card = new Omnipay\Common\CreditCard($cardInput);

这就是有关键字use的原因。

This is good topic source.

【讨论】:

    猜你喜欢
    • 2016-03-07
    • 2016-05-23
    • 2014-03-29
    • 2016-01-28
    • 2013-08-31
    • 2016-03-18
    • 2015-07-03
    • 1970-01-01
    • 2010-09-05
    相关资源
    最近更新 更多