nguoingulanh / paypal-panel

支付 PayPal ...

dev-main 2023-03-27 08:59 UTC

This package is auto-updated.

Last update: 2024-09-27 12:27:17 UTC


README

  • 从 PayPal 检查 out SDK 获取

https://developer.paypal.com/api/rest/authentication/
https://developer.paypal.com/docs/api/orders/v2/

配置

要开始,您应该使用 setup construct 发布 config/paypal-panel.php 配置文件

php artisan vendor:publish --provider="PaypalPanel\ServiceProvider"

结构设置

    public $client;

    public function __construct()
    {
        $paypalConfigs = config('paypal-panel');

        $env = new SandboxEnvironment($paypalConfigs['client_id'], $paypalConfigs['secret']);
        $mode = 'sandbox';

        //live
        // $env = new ProductionEnvironment($paypalConfigs['client_id'], $paypalConfigs['secret']);
        // $mode = 'live';

        $this->environment = $env;
        $this->client = new PayPalHttpClient($this->environment);
    }

代码

use PaypalPanel\Order\OrdersCreateRequest;
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
                     "intent" => "CAPTURE",
                     "purchase_units" => [[
                         "reference_id" => "test_ref_id1",
                         "amount" => [
                             "value" => "100.00",
                             "currency_code" => "USD"
                         ]
                     ]],
                     "application_context" => [
                          "cancel_url" => "https://example.com/cancel",
                          "return_url" => "https://example.com/return"
                     ] 
                 ];

try {
    // Call API with your client and get a response for your call
    $response = $client->execute($request);
    
    // If call returns body in response, you can get the deserialized version from the result attribute of the response
    print_r($response);
}catch (HttpException $ex) {
    echo $ex->statusCode;
    print_r($ex->getMessage());
}