// Replace with your actual PayPal API credentials
$api_username = "";
$api_password = "";
$api_signature = "";
// PayPal API endpoint (sandbox or live)
$api_endpoint = "https://api-3t.paypal.com/nvp"; // Live endpoint
// For sandbox testing: $api_endpoint = "https://api-3t.sandbox.paypal.com/nvp";
// Prepare API request parameters
$params = array(
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'METHOD' => 'GetBalance', // You can change this to test other methods
'VERSION' => '204.0',
);
// Initialize cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
exit;
}
// Close cURL session
curl_close($ch);
// Parse response
parse_str($response, $responseArray);
// Check API response
if ($responseArray['ACK'] == 'Success') {
echo "API call successful!\n";
echo "Response:\n";
print_r($responseArray);
} else {
echo "API call failed!\n";
echo "Error message: " . $responseArray['L_LONGMESSAGE0'] . "\n";
}
Created
August 31, 2023 13:28
-
-
Save DominicWatts/97dbd56ced13d8b60a664a0c839e358e to your computer and use it in GitHub Desktop.
PHP : Paypal API test script #php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment