第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Laravel Paypal 付款。怎樣才能讓它完整呢?它返回 json 響應(yīng)

Laravel Paypal 付款。怎樣才能讓它完整呢?它返回 json 響應(yīng)

PHP
呼如林 2023-08-06 15:41:15
我已經(jīng)使用他們的文檔創(chuàng)建了單批付款。這樣我就可以匯款給賣家。但我不知道之后我應(yīng)該做什么。如何顯示付款表格,用戶可以在其中登錄 PayPal 并支付金額?這是我在控制器功能中的代碼?public function payViaPaypal(){? ?? ? ? ? $payouts = new \PayPal\Api\Payout();? ? ? ? $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();? ? ? ? $senderBatchHeader->setSenderBatchId(uniqid('invoice-1qaqw23wdwdwew').microtime('true'))? ? ? ? ? ? ->setEmailSubject("You have a Payout!");? ? ? ? $senderItem = new \PayPal\Api\PayoutItem();? ? ? ? $senderItem->setRecipientType('Email')? ? ? ? ? ? ->setNote('Thanks for your patronage!')? ? ? ? ? ? ->setReceiver('sb-cwdzv2614448@business.example.com')? ? ? ? ? ? ->setSenderItemId(uniqid().microtime('true'))? ? ? ? ? ? ->setAmount(new \PayPal\Api\Currency('{? ? ? ? ? ? ? ? ? ? ? ? "value":"1.0",? ? ? ? ? ? ? ? ? ? ? ? "currency":"USD"? ? ? ? ? ? ? ? ? ? }'));? ? ? ? $payouts->setSenderBatchHeader($senderBatchHeader)? ? ? ? ? ? ->addItem($senderItem);? ? ? ? $request = clone $payouts;? ? ? ? $redirect_url = null;? ? ? ? try {? ? ? ? ? ? $output = $payouts->create(null, $this->api_context);? ? ? ? } catch (\Exception $e) {? ? ? ? ? ? dd('here',$this->errorDetails($e));? ? ? ? }//? ? ? ? dd("Created Single Synchronous Payout", "Payout", $output->getBatchHeader()->getPayoutBatchId(), $request, $output);? ? ? ? $redirect_url = null;? ? ? ? foreach($output->getLinks() as $link) {? ? ? ? ? ? if($link->getRel() == 'self') {? ? ? ? ? ? ? ? $redirect_url = $link->getHref();? ? ? ? ? ? ? ? break;? ? ? ? ? ? }? ? ? ? }? ? ? ? return $output;}當(dāng)我點(diǎn)擊路由訪問(wèn)此代碼時(shí),我收到此 json 響應(yīng)。{ "batch_header": { "payout_batch_id": "79CTFV2X5TS58", "batch_status": "PENDING", "sender_batch_header": { "sender_batch_id": "invoice-1qaqw23wdwdwew5f0f5003612091594839043.3978", "email_subject": "You have a Payout!" } }, "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payouts/79CTFV2X5TS58", "rel": "self", "method": "GET", "enctype": "application/json" } ] }我希望用戶將被帶到 PayPal 付款頁(yè)面,用戶將在該頁(yè)面登錄并支付金額,然后 PayPal 會(huì)通知我有關(guān)付款的信息。但我試圖通過(guò)互聯(lián)網(wǎng)找到解決方案,但我找不到示例/解決方案。
查看完整描述

2 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

付款用于將資金從您的帳戶發(fā)送到另一個(gè)帳戶。沒有可顯示或登錄的表格。您是 API 調(diào)用者,系統(tǒng)會(huì)自動(dòng)批準(zhǔn)來(lái)自您帳戶的付款。


查看完整回答
反對(duì) 回復(fù) 2023-08-06
?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

解決方案是創(chuàng)建一個(gè)付款對(duì)象并在其中添加收款人(將作為賣家接收付款)電子郵件地址。

需要兩個(gè)函數(shù)。

1 創(chuàng)建付款對(duì)象 2 使用 API 從 paypal 獲取付款詳細(xì)信息,然后執(zhí)行此付款,以便將金額轉(zhuǎn)入收款賬戶。

以下需要 3 條路線

  1. 創(chuàng)建支付對(duì)象

  2. 獲取詳細(xì)付款對(duì)象詳細(xì)信息(查看客戶是否已使用 paypal 結(jié)賬支付金額)并執(zhí)行付款以匯款(這是成功 url)

  3. 取消網(wǎng)址(當(dāng)客戶取消付款時(shí))。它將客戶重定向回平臺(tái)(網(wǎng)站)

這是完整的代碼示例

路線

create payment object

Route::get('/invoices/process-payment','Vendor\PayPalController@processPaymentInvoiceViaCheckout');


when payment object is created then get its details and execute payment to send money.

Route::get('/invoices/response-success','Vendor\PayPalController@paypalResponseSuccess');


when cancel to pay?

Route::get('/invoices/response-cancel','Vendor\PayPalController@paypalResponseCancel');


控制器


<?php


namespace App\Http\Controllers\Vendor;


use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use PayPal\Api\Amount;

use PayPal\Api\Details;

use PayPal\Api\Item;

use PayPal\Api\ItemList;

use PayPal\Api\Payee;

use PayPal\Api\Payer;

use PayPal\Api\Payment;

use PayPal\Api\PaymentExecution;

use PayPal\Api\RedirectUrls;

use PayPal\Api\Transaction;

use PayPal\Auth\OAuthTokenCredential;

use PayPal\Exception\PayPalConnectionException;

use PayPal\Rest\ApiContext;

use PHPUnit\TextUI\ResultPrinter;


class PayPalController extends Controller


{

? ? private $api_context;


? ? public function __construct()

? ? {

? ? ? ? $this->api_context = new ApiContext(

? ? ? ? ? ? new OAuthTokenCredential(config('paypal.client_id'), config('paypal.secret'))

? ? ? ? );

? ? ? ? $this->api_context->setConfig(config('paypal.settings'));

? ? }

? ? public function processPaymentInvoiceViaCheckout(){

? ? ? ? $payer = new Payer();

? ? ? ? $payer->setPaymentMethod("paypal");


? ? ? ? $item1 = new Item();

? ? ? ? $item1->setName('Ground Coffee 40 oz')

? ? ? ? ? ? ->setCurrency('USD')

? ? ? ? ? ? ->setQuantity(1)

//? ? ? ? ? ? ->setSku("123123") // Similar to `item_number` in Classic API

? ? ? ? ? ? ->setPrice(7.5);

? ? ? ? $item2 = new Item();

? ? ? ? $item2->setName('Granola bars')

? ? ? ? ? ? ->setCurrency('USD')

? ? ? ? ? ? ->setQuantity(5)

//? ? ? ? ? ? ->setSku("321321") // Similar to `item_number` in Classic API

? ? ? ? ? ? ->setPrice(2);


? ? ? ? $itemList = new ItemList();

? ? ? ? $itemList->setItems(array($item1, $item2));

? ? ? ? $details = new Details();

? ? ? ? $details->setShipping(1.2)

? ? ? ? ? ? ->setTax(1.3)

? ? ? ? ? ? ->setSubtotal(17.50);

? ? ? ? $amount = new Amount();

? ? ? ? $amount->setCurrency("USD")

? ? ? ? ? ? ->setTotal(20)

? ? ? ? ? ? ->setDetails($details);

? ? ? ? $payee = new Payee();


? ? ? ? //this is the email id of the seller who will receive this amount


? ? ? ? $payee->setEmail("seller-paypal-businness-account-email@business.example.com");

? ? ? ? $transaction = new Transaction();

? ? ? ? $transaction->setAmount($amount)

? ? ? ? ? ? ->setItemList($itemList)

? ? ? ? ? ? ->setDescription("Payment description")

? ? ? ? ? ? ->setPayee($payee)

? ? ? ? ? ? ->setInvoiceNumber(uniqid());

? ? ? ? $redirectUrls = new RedirectUrls();

? ? ? ? $redirectUrls->setReturnUrl(url('/invoices/response-success'))

? ? ? ? ? ? ->setCancelUrl(url('/invoices/response-cancel'));

? ? ? ? $payment = new Payment();

? ? ? ? $payment->setIntent("sale")

? ? ? ? ? ? ->setPayer($payer)

? ? ? ? ? ? ->setRedirectUrls($redirectUrls)

? ? ? ? ? ? ->setTransactions(array($transaction));

? ? ? ? $request = clone $payment;

? ? ? ? try {

? ? ? ? ? ? //create payment object

? ? ? ? ? ? $createdPayment = $payment->create($this->api_context);

? ? ? ? ? ? //get payment details to get payer id so that payment can be executed and transferred to seller.

? ? ? ? ? ? $paymentDetails = Payment::get($createdPayment->getId(), $this->api_context);

? ? ? ? ? ? $execution = new PaymentExecution();

? ? ? ? ? ? $execution->setPayerId($paymentDetails->getPayer());

? ? ? ? ? ? $paymentResult = $paymentDetails->execute($execution,$this->api_context);

? ? ? ? } catch (\Exception $ex) {

? ? ? ? ? ? //handle exception here

? ? ? ? }

? ? ? ? //Get redirect url

? ? ? ? //The API response provides the url that you must redirect the buyer to. Retrieve the url from the $payment->getApprovalLink() method

? ? ? ? $approvalUrl = $payment->getApprovalLink();


? ? ? ? return redirect($approvalUrl);

? ? }


? ? public function paypalResponseCancel(Request $request)

? ? {


? ? ? ? //normally you will just redirect back customer to platform

? ? ? ? return redirect('invoices')->with('error','You can cancelled payment');

? ? }


? ? public function paypalResponseSuccess(Request $request)

? ? {

? ? ? ? if (empty($request->query('paymentId')) || empty($request->query('PayerID')) || empty($request->query('token'))){

? ? ? ? ? ? //payment was unsuccessful

? ? ? ? ? ? //send failure response to customer

? ? ? ? }

? ? ? ? $payment = Payment::get($request->query('paymentId'), $this->api_context);

? ? ? ? $execution = new PaymentExecution();

? ? ? ? $execution->setPayerId($request->query('PayerID'));


? ? ? ? // Then we execute the payment.

? ? ? ? $result = $payment->execute($execution, $this->api_context);



? ? ? ? dd($request->all(),$result);

? ? ? ?//payment is received,? send response to customer that payment is made.

? ? }

}

查看完整回答
反對(duì) 回復(fù) 2023-08-06
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)