1

我正在尝试使用 Eloquent 在 Laravel 4.1 中保存 de Payment 详细信息。我试图创建我的模型,如文档 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),
    )
);

控制器/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
{
}

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

4

1 回答 1

0

[来自评论]

您的示例表明您使用文件系统存储,但您需要 Eloquent 存储。此类存储并非开箱即用,但我们计划在不久的将来添加它。

[回答]

仓库现在在这里。以下是您必须修改配置以使用它的方法:

<?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),
    )
);

这是文档

于 2015-02-16T15:47:34.203 回答