doubutao6216 2018-02-16 19:57
浏览 77

PayPal单一付款到电子邮件

I am trying to integrate PayPal's Payout option to be able to pay users directly by providing their email.

I am calling the controller function through a form with POST method, after I call the simplePay function, all I get is a blank page, I would like to know if what I'm doing is correct, incomplete (and what its lacking), or wrong (and what am I doing wrong).

I've based my research on code samples provided by Paypal Documentation. https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payouts/CreateBatchPayout.php

Route:

Route::post('/simplePay', 'PaypalController@simplePay');

Controller:

    <?php
    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use PayPal\Rest\ApiContext;
    use PayPal\Api\Amount;
    use PayPal\Api\Details;
    use PayPal\Api\Item;
    use PayPal\Api\ItemList;
    use PayPal\Api\Payer;
    use PayPal\Api\Payment;
    use PayPal\Api\Transaction;
    use PayPal\Api\RedirectUrls;
    use PayPal\Api\ExecutePayment;
    use PayPal\Api\PaymentExecution;
    use PayPal\Auth\OAuthTokenCredential;

    class PaypalController extends Controller
    {

      private $_api_context;
        public function __construct()
        {
            // setup PayPal api context
            $paypal_conf = \Config::get('paypal');
            $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
            $this->_api_context->setConfig($paypal_conf['settings']);
        }
        public function simplePay()
        {
            $payouts = new \PayPal\Api\Payout();
            $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
            $senderBatchHeader->setSenderBatchId(uniqid())->setEmailSubject("You have a Payout!");
            $senderItem = new \PayPal\Api\PayoutItem();
            $senderItem->setRecipientType('Email')->setNote('Thanks for your patronage!')->setReceiver('email@gmail.com')->setSenderItemId("001")->setAmount(new \PayPal\Api\Currency('{
                                    "value":"1.00",
                                    "currency":"MXN"
                                }'));
            $payouts->setSenderBatchHeader($senderBatchHeader)->addItem($senderItem);
            $request = clone $payouts;
            try {
                $output = $payouts->createSynchronous($this->_api_context);
            } catch (\Exception $ex) {
                //  \ResultPrinter::printError("Created Single Synchronous Payout", "Payout", null, $request, $ex);
                exit(1);
            }
            // \ResultPrinter::printResult("Created Single Synchronous Payout", "Payout", $output->getBatchHeader()->getPayoutBatchId(), $request, $output);
            return $output;
        }
    }

Call to controller:

                    <div class="row">
                        <form class="form-horizontal" role="form" enctype="multipart/form-data" method="POST" action="{{ url('/simplePay') }}">
                        {{csrf_field()}}

                        <input type="submit" name="submit" value="Pay">
                        </form>

                    </div>

paypal.php - app/config file - Just in Case:

<?php
return array(
    // set your paypal credential
    'client_id' => 'AXs...',
    'secret' => 'AHE...',

    /**
     * SDK configuration
     */
    'settings' => array(
        /**
         * Available option 'sandbox' or 'live'
         */
        'mode' => 'sandbox',

        /**
         * Specify the max request time in seconds
         */
        'http.ConnectionTimeOut' => 12000,

        /**
         * Whether want to log to a file
         */
        'log.LogEnabled' => true,

        /**
         * Specify the file that want to write on
         */
        'log.FileName' => storage_path() . '/logs/paypal.log',

        /**
         * Available option 'FINE', 'INFO', 'WARN' or 'ERROR'
         *
         * Logging is most verbose in the 'FINE' level and decreases as you
         * proceed towards ERROR
         */
        'log.LogLevel' => 'FINE'
    ),
);
  • 写回答

1条回答 默认 最新

  • duanmian1085 2018-11-28 02:38
    关注

    PayPal sync mode is not available for new integrations. Existing integrations will continue to function if your passing "sync_mode = true".

    To solve the issue, you need to pass "sync_mode = false" so instead of

    $output = $payouts->createSynchronous($this->_api_context);
    

    use the following:

    $output = $payouts->create(array('sync_mode' => 'false'), $this->_api_context);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题