付款优惠,Mercadopago的SDK& Laravel 5.5

时间:2018-01-24 14:58:21

标签: laravel mercadopago

我在整合MercadoPago的SDK和Laravel 5.5时遇到了问题

错误讯息:

MercadoPagoException(400) 参数数量错误

屏幕:

error screen

付款控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\Cart;
use Exception;
use MP;

class PaymentController extends Controller
{
  /**
   * Display a listing of the resource.
   *
   * @return Response
   */
  public function process(Request $request)
  {

    $mp = new MP (env('MP_CLIENT_ID'), env('MP_CLIENT_SECRET'));

    $user = auth()->user();
    $prefix = 'VSHOPREF-';
    $external_reference = $prefix . $request->ctoken;
    $token = $request->ctoken;

    $preferenceData = [
        'external_reference' => $external_reference,
        'payer'              => [
            'name' => $user->name,
            'email' => $user->email
        ],
        'back_urls' => [
        'success' => env('APP_URL').'/gracias',
        'pending' => env('APP_URL').'/gracias',
        'failure' => env('APP_URL').'/error'
        ],
        'notification_url' => env('MP_NOTIFICATION_URL'),
        'auto_return' => 'all'
    ];

    $entries = Cart::where('session_id', '=', $token)->get();
    foreach ($entries as $e):
        $preferenceData['items'][] = [
            'title'       => $e->product_name,
            'category_id' => 'zapato',
            'quantity'    => $e->qty,
            'currency_id' => 'VEF',
            'unit_price'  => $e->price,
        ];
    endforeach;

    //dd($preferenceData);
    $preference = $mp->create_preference($preferenceData);
    dd($preference);

    //return init point to be redirected
    //return $preference['response']['init_point'];

  }
}

表单我用来发送付款信息

<form class="form-horizontal" action="{!! route('payment.process') !!}" method="post">
                {{ csrf_field() }}
                <input type="hidden" name="ctoken" id="ctoken" value="{!! $cart_token !!}">
                <input type="submit" name="pagar" value="Pagar" class="btn btn-success btn-block btn-sm">
              </form>
顺便说一句,我很抱歉我的英语不好。我希望你能帮我解决这个问题。

编辑1

感谢Alexey Mezenin

好吧,我在.env文件上写了“MP_CIENT_SECRET”而不是“MP_CLIENT_SECRET”。

新错误

MercadoPagoException(400) currency_id无效

0 个答案:

没有答案