PayPal
Setting up a Paypal REST Profile
In the Tools > API menu, you can create API profiles for use in your projects. This way, you will only need to provide your credentials once to use the API in your project.
Access the official documentation to obtain the necessary credentials for this profile.

When deploying your project, you will need to configure the API credentials in Prod, by accessing the API menu.
Name
Defines the name to identify the API profile. This name is unique and will be used to reference the API profile in your project’s applications.
Mode
The mode defines the availability of the profile in Scriptcase.
-
Public - Users from all projects will be able to view and use the created profile.
-
Project - Users will be able to view and use the profile in the project where it was configured.
-
User - Only the user who created the profile will be able to view and use it in the applications.
Gateway
Defines the API that will be used to create the profile.
Auth ClientID
Client ID of the PayPal account;
Auth Secret
Authentication key of the PayPal account;
Test Mode
Allows using the API in test mode.
Example of payment via PayPal
// Example of use in Scriptcase to create a PayPal payment via API
// First, calls the API with the configured profile
$gateway = sc_call_api('paypal_profile_name'); // replace with the name you gave in Scriptcase
// Defines the payment details
$payment = $gateway->create();
// Transaction amount
$payment->amount = '50.00'; // amount to be paid (e.g., USD or another currency as configured)
$payment->currency = 'USD'; // currency
$payment->description = 'Purchase of product X';
// Buyer (payer) data
$payment->payer = array(
'first_name' => 'João',
'last_name' => 'Silva',
'email' => 'joao.silva@exemplo.com'
);
// URLs for redirection after payment
$payment->return_url = 'https://yoursite.com/paypal_return';
$payment->cancel_url = 'https://yoursite.com/cancel_paypal';
// Creates the transaction in PayPal
$response = $payment->save();
// Optional: Redirects the user to PayPal to approve the payment
if (isset($response->approval_url)) {
header('Location: ' . $response->approval_url);
exit;
}
// For debugging, you can display the response
echo '<pre>';
print_r($response);
exit;
Example of expected return from the PayPal API
{
"id": "5O190127TN364715T",
"status": "CREATED",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=5O190127TN364715T",
"rel": "approve",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T/capture",
"rel": "capture",
"method": "POST"
}
],
"payer": {
"name": {
"given_name": "João",
"surname": "Silva"
},
"email_address": "joao.silva@exemplo.com",
"payer_id": "PAYERID12345",
"address": {
"country_code": "BR"
}
},
"purchase_units": [
{
"reference_id": "default",
"amount": {
"currency_code": "USD",
"value": "50.00"
},
"payee": {
"email_address": "vendedor@exemplo.com"
}
}
]
}