HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //www/wwwroot/jf.cwoyt.com/1.php
<?php

// API endpoint

// 获取 Access Token 
$clientId = 'AV215uV-cE-AZ9nd4dNWf24vzrj6UyvA3rA8FDGVW09Y531j9H3GO7FtJmphimXNwisgYNHFvW-6wYMo';
$clientSecret = 'EJb5xUSW8QtuPJeaHuOjAXl9WXp2kj4-zkym-7fXCBM-TssNhkK2FB1-iJOmxYsGcASO8zBTHaPRoJH_';
$paypalRequestId = $clientId;

// PayPal API 认证 URL (沙盒环境)
$authUrl = "https://api.sandbox.paypal.com/v1/oauth2/token";

// 创建认证信息
$auth = base64_encode($clientId . ":" . $clientSecret);

// 初始化 cURL
$ch = curl_init();

// 设置 cURL 请求选项
curl_setopt($ch, CURLOPT_URL, $authUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Basic $auth",
    "Content-Type: application/x-www-form-urlencoded"
]);

// 设置请求体
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

// 执行 cURL 请求
$response = curl_exec($ch);
curl_close($ch);

// 解析响应并获取访问令牌
$data = json_decode($response, true);
$accessToken = $data['access_token']; 

// Access Token and other headers

$url = "https://api.sandbox.paypal.com/v2/checkout/orders/";

// Create the request body as JSON
$data = [
    "intent" => "CAPTURE",
    "payment_source" => [
        "card" => [
            'type' => 'visa', // 卡片类型,支持:visa, masterCard, amex 等
            "number" => "4111111111111111", // 使用沙盒测试卡号 
            'expire_month' => 12, // 卡片过期月份
                    'expire_year' => 2025, // 卡片过期年份
                    'cvv' => '123', // 卡片的 CVV2 安全码
            "name" => "Firstname Lastname",
            "billing_address" => [
                "address_line_1" => "123 Main St.",
                "admin_area_1" => "CA",
                "admin_area_2" => "Anytown",
                "postal_code" => "12345",
                "country_code" => "US"
            ]
        ]
    ],
    "purchase_units" => [
        [
            "reference_id" => "REFID-000-1001",
            "description" => "Description of PU1",
            "custom_id" => "CUSTOMID-1001",
            "soft_descriptor" => "SOFT-1001",
            "amount" => [
                "currency_code" => "USD",
                "value" => "100.00",
                "breakdown" => [
                    "item_total" => [
                        "currency_code" => "USD",
                        "value" => "100.00"
                    ],
                    "shipping" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ],
                    "handling" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ],
                    "tax_total" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ],
                    "shipping_discount" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ]
                ]
            ],
            "items" => [
                [
                    "name" => "VRLens2",
                    "description" => "VRLens2",
                    "sku" => "259483234816",
                    "unit_amount" => [
                        "currency_code" => "USD",
                        "value" => "50.00"
                    ],
                    "tax" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ],
                    "quantity" => "1",
                    "category" => "PHYSICAL_GOODS"
                ],
                [
                    "name" => "VRLens1",
                    "description" => "VRLens1",
                    "sku" => "259483234817",
                    "unit_amount" => [
                        "currency_code" => "USD",
                        "value" => "50.00"
                    ],
                    "tax" => [
                        "currency_code" => "USD",
                        "value" => "0"
                    ],
                    "quantity" => "1",
                    "category" => "PHYSICAL_GOODS"
                ]
            ],
            "shipping" => [
                "name" => [
                    "full_name" => "Firstname Lastname"
                ],
                "address" => [
                    "address_line_1" => "123 Main St.",
                    "admin_area_2" => "Anytown",
                    "admin_area_1" => "CA",
                    "postal_code" => "12345",
                    "country_code" => "US"
                ]
            ]
        ]
    ]
];

// Convert the data to JSON
$jsonData = json_encode($data);

// Initialize cURL session
$ch = curl_init($url);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $accessToken,
    'PayPal-Request-Id: ' . $paypalRequestId
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

// Execute the cURL request and get the response
$response = curl_exec($ch);

// Check for cURL errors
if(curl_errno($ch)) {
    echo 'Curl error: ' . curl_error($ch);
} else {
    // Handle the response
    echo $response;
}

// Close cURL session
curl_close($ch);
?>