我尝试在本地将“srmklive/paypal”:“〜1.0”实施到我的laravel项目中,在测试实施时,我在下面遇到错误

Posted

技术标签:

【中文标题】我尝试在本地将“srmklive/paypal”:“〜1.0”实施到我的laravel项目中,在测试实施时,我在下面遇到错误【英文标题】:i tried implementing "srmklive/paypal": "~1.0", into my laravel project locally, while testing the implementation, i got an error below 【发布时间】:2021-03-03 19:25:49 【问题描述】:

未定义的索引:秘密 lluminate\Foundation\Bootstrap\HandleExceptions::handleError C:\wamp64\www\chefruntown\vendor\srmklive\paypal\src\Traits\PayPalRequest.php:329

private function setApiProviderConfiguration($credentials)
    // Setting PayPal API Credentials

    collect($credentials[$this->mode])->map(function ($value, $key) 

        $this->config[$key] = $value;

    );


    // Setup PayPal API Signature value to use.

    $this->config['signature'] = empty($this->config['certificate']) ?

    $this->config['secret'] : $this->config['certificate'];

    $this->paymentAction = $credentials['payment_action'];

    $this->locale = $credentials['locale'];

    $this->certificate = $this->config['certificate'];

    $this->validateSSL = $credentials['validate_ssl'];

    $this->setApiProvider($credentials);

【问题讨论】:

请分享设置paypal凭据的代码。 【参考方案1】:

我用这个更新了在我的配置文件夹中找到的 paypal.php 文件

<?php
/**
 * PayPal Setting & API Credentials
 * Created by Raza Mehdi <srmk@outlook.com>.
 */

return [
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
    'sandbox' => [
        'username'    => env('PAYPAL_SANDBOX_API_USERNAME', ''),
        'password'    => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
        'secret'      => env('PAYPAL_SANDBOX_API_SECRET', ''),
        'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
        'app_id'      => 'APP-80W284485P519543T', // Used for testing Adaptive Payments API in sandbox mode
    ],
    'live' => [
        'username'    => env('PAYPAL_LIVE_API_USERNAME', ''),
        'password'    => env('PAYPAL_LIVE_API_PASSWORD', ''),
        'secret'      => env('PAYPAL_LIVE_API_SECRET', ''),
        'certificate' => env('PAYPAL_LIVE_API_CERTIFICATE', ''),
        'app_id'      => '', // Used for Adaptive Payments API
    ],

    'payment_action' => 'Sale', // Can only be 'Sale', 'Authorization' or 'Order'
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
    'billing_type'   => 'MerchantInitiatedBilling',
    'notify_url'     => '', // Change this accordingly for your application.
    'locale'         => '', // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
    'validate_ssl'   => true, // Validate SSL when creating api client.
];

【讨论】:

【参考方案2】:

基本上,你需要匹配.env变量和config/paypa.php变量。

PAYPAL_MODE=sandbox
PAYPAL_CURRENCY=USD
PAYPAL_SANDBOX_API_USERNAME=username
PAYPAL_SANDBOX_API_PASSWORD=password
PAYPAL_SANDBOX_API_SECRET=secret-key-or-signature

您可以通过导航至paypal sandbox dashboard &gt; leftnav &gt; accounts &gt; sandbox &gt; list of account &gt; view/edit account (action drop down) &gt; API Credentials tab 来检索这些信息。

你的 config/paypal.php 应该传递相同的变量。

return [
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
    'sandbox' => [
        'username'    => env('PAYPAL_SANDBOX_API_USERNAME', ''),
        'password'    => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
        'secret'      => env('PAYPAL_SANDBOX_API_SECRET', ''),
        'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
        'app_id'      => 'APP-80W284485P519543T',
        // 'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
        // 'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
        // 'app_id'            => 'APP-80W284485P519543T',
    ],
    'live' => [
        // 'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
        // 'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
        // 'app_id'            => '',
        'username'    => env('PAYPAL_SANDBOX_API_USERNAME', ''),
        'password'    => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
        'secret'      => env('PAYPAL_SANDBOX_API_SECRET', ''),
        'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
        'app_id'      => '',
    ],

    'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
    'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
    'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
    'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
];

注意沙盒和实时数组,我已经用新的注释了默认数组项。

【讨论】:

以上是关于我尝试在本地将“srmklive/paypal”:“〜1.0”实施到我的laravel项目中,在测试实施时,我在下面遇到错误的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Laravel 8 中使用 srmklive/laravel-paypal v3

与paypal集成时如何解决paypal登录选项卡丢失的问题

(Laravel)无法从PayPal IPN获得响应,但模拟的响应返回已经过验证

使用 API 设置 PayPal IPN URL

将数据保存到本地存储

我正在尝试将我的本地 spring boot 应用程序连接到我的 heroku postgres db