laravel - Payum - Laravel 4 的包。如何使用 Eloquent 而不是 FilesystemStorage 创建模型数据?

标签 laravel paypal payum

我尝试使用 Eloquent 在 Laravel 4.1 中保存付款详细信息。我试过像 documentation payum 所说的那样创建我的模型,但它对我不起作用。我的代码:

payum/payum-laravel-package/config.php:

<?php

use Payum\Core\Storage\FilesystemStorage;
use Payum\Paypal\ExpressCheckout\Nvp\Api;
use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory as PaypalPaymentFactory;

$detailsClass = 'Payum\Core\Model\ArrayObject';
$tokenClass = 'Payum\Core\Model\Token';

$paypalPayment = PaypalPaymentFactory::create(new Api(array(
    'username' => 'MY_USER_NAME',
    'password' => 'MY_PASS',
    'signature' => 'MY_SIGN',
    'sandbox' => true
)));

return array(
    'token_storage' => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $tokenClass, 'hash'),
    'payments' => array(
        'paypal_es' => $paypalPayment,
    ),
    'storages' => array(
        $detailsClass => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $detailsClass),
    )
);

Controller /PaypalController.php

<?php

use Payum\Paypal\ExpressCheckout\Nvp\Api;

class PaypalController extends BaseController
{
    public function prepareExpressCheckout()
    {

       $paymentName = 'paypal_es';

       $storage = \App::make('payum')->getStorage('Payum\Core\Model\ArrayObject');

         /** @var $paymentDetails PaymentDetails */
           $paymentDetails = $storage->createModel();
           $paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
           $paymentDetails['PAYMENTREQUEST_0_AMT'] = '1.21';
           $paymentDetails['NOSHIPPING'] = Api::NOSHIPPING_NOT_DISPLAY_ADDRESS;
           $paymentDetails['REQCONFIRMSHIPPING'] = Api::REQCONFIRMSHIPPING_NOT_REQUIRED;
           $paymentDetails['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = Api::PAYMENTREQUEST_ITERMCATEGORY_DIGITAL;
           $paymentDetails['L_PAYMENTREQUEST_0_AMT0'] = '1.21';
           $paymentDetails['L_PAYMENTREQUEST_0_QTY0'] = '1';
           $paymentDetails['L_PAYMENTREQUEST_0_NAME0'] = 'Modulo 1';
           $paymentDetails['L_PAYMENTREQUEST_0_DESC0'] = 'Descripción Módulo 1';
           $storage->updateModel($paymentDetails);

            $captureToken = \App::make('payum.security.token_factory')->createCaptureToken($paymentName, $paymentDetails, 'payment_done');

           $paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
           $paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
         //  $paymentDetails['INVNUM'] = $paymentDetails->getId();
           $storage->updateModel($paymentDetails);

       return \Redirect::to($captureToken->getTargetUrl());
    }

    /**
     * @return \Payum\Core\Security\GenericTokenFactoryInterface
     */
    protected function getTokenFactory()
    {
        return \App::make('payum.security.token_factory');
    }
}

此代码运行良好,但我想使用 Eloquent 而不是 FilesystemStorage 创建我自己的模型。我已尝试遵循 Payum 文档,但对我不起作用:

<?php
namespace App\Model;

use Payum\Core\Model\ArrayObject;

class PaymentDetails extends ArrayObject
{
    protected $id;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
}

use Payum\Core\Model\Token;

class PaymentSecurityToken extends Token
{
}

我该怎么做?任何帮助将不胜感激,因为我没有想法。

最佳答案

[来自comment ]

Your examples show that you use filesystem storage, but you need Eloquent one. Such storage does not provided out of the box, but we have plans to add it in near future.

[回答]

现在存储在这里。以下是您必须如何修改配置才能使用它:

<?php

use Payum\LaravelPackage\Storage\EloquentStorage;
use Payum\Paypal\ExpressCheckout\Nvp\PaymentFactory;

// it is not same model as you used but you get the idea.
$detailsClass = 'Payum\LaravelPackage\Model\Order';
$tokenClass = 'Payum\LaravelPackage\Model\Token';

$paymentFactory = new PaymentFactory();

return array(
    'token_storage' => new EloquentStorage($tokenClass),
    'payments' => array(
        'paypal' => $paymentFactory->create(array(
            'username' => 'MY_USER_NAME',
            'password' => 'MY_PASS',
            'signature' => 'MY_SIGN',
            'sandbox' => true
        ));,
    ),
    'storages' => array(
        $detailsClass => new EloquentStorage($detailsClass),
    )
);

这是 documentation .

关于laravel - Payum - Laravel 4 的包。如何使用 Eloquent 而不是 FilesystemStorage 创建模型数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25200236/

相关文章:

php - laravel 中的存储库模式相对于在 Controller 构造函数中实例化模型的优势

laravel - 如何使用 Composer 安装 Laravel 4

php - Laravel 过滤已经过滤的结果

php - Paypal 网址无法正常工作

paypal - 是否可以将任何个人对个人支付服务整合到我的市场中,从而我也可以为自己收取一定比例的费用?

symfony - payum symfony 2 bundle - 基本配置 - 存储

php - 在 Laravel Eloquent 中查询只有日期的日期时间字段

jquery - 如何将 PayPal 表单输入的值更改为用户通过文本输入给出的值

express - Payum Paypal Express 结账详情

php - Payum Bundle 发送空付款 - Paypal 接受它 :) :(