Limited time offers! Get up to 20% OFF.

Stripe

Stripe is a payment gateway that allows individuals or businesses to receive online payments.

To use this API, you need an account. Here is the link to log in or create a new account if you don’t have one: https://dashboard.stripe.com/login

Setting up a Profile

In the menu Tools > API 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.

See how to obtain the credentials needed to configure the profile.

When deploying your project, you will need to configure the API credentials in Prod, by accessing the API menu.

Configuração de pagamento utilizando API Stripe

When deploying your project, you will need to configure the API credentials in Prod, by accessing the API menu.

To create a profile, we must add the following information:

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.

Regardless of the mode used for creation, profiles can only be edited by users with administrator access in the project. See how to define user access levels in Scriptcase.

Gateway

Defines the API that will be used to create the profile.

API Key

Enter the API secret key

Secret Key

  • Test Mode Secret Key: Use this key to authenticate requests to your server when in test mode. By default, you can use this key to make any API request without restriction.

  • Production Mode Secret Key: Use this key to authenticate requests to your server when in production mode. By default, you can use this key to make any API request without restriction.

Public Key

  • Test Mode Publishable Key: Use this key for testing purposes in the client-side code of your mobile application.

  • Production Mode Publishable Key: Use this key when you are ready to launch your application, in the client-side code of your mobile or web application.

Usage Example

See below for some examples of API usage.

Example using the API profile in the sc_call_api macro

// Chamada da Macro utilizando perfil da API
$gateway = sc_call_api('stripe');

// Passando os valores, descrição e tipo de pagamento.
$gateway->charges->create([
  'amount' => 2000,
  'currency' => 'brl',
  'source' => 'tok_mastercard',
  'description' => 'My First Test Charge with Scriptcase',
]);

Exemplo de retorno da API

{
  "id": "ch_3M9wLeLZM9w2hLeLZ4yW2h",
  "object": "charge",
  "amount": 2000,
  "amount_captured": 2000,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "application_fee_amount": null,
  "balance_transaction": "txn_3M9wLeLZM9w2hLeLZ",
  "billing_details": {
    "address": {
      "city": null,
      "country": null,
      "line1": null,
      "line2": null,
      "postal_code": null,
      "state": null
    },
    "email": null,
    "name": null,
    "phone": null
  },
  "calculated_statement_descriptor": "Stripe",
  "captured": true,
  "created": 5555555555,
  "currency": "brl",
  "customer": null,
  "description": "My First Test Charge with Scriptcase",
  "destination": null,
  "dispute": null,
  "disputed": false,
  "failure_balance_transaction": null,
  "failure_code": null,
  "failure_message": null,
  "fraud_details": {
  },
  "invoice": null,
  "livemode": false,
  "metadata": {
  },
  "on_behalf_of": null,
  "order": null,
  "outcome": {
    "network_status": "approved_by_network",
    "reason": null,
    "risk_level": "normal",
    "risk_score": 36,
    "seller_message": "Payment complete.",
    "type": "authorized"
  },
  "paid": true,
  "payment_intent": null,
  "payment_method": "card_3M9wLeLZM9w2hLeLZ",
  "payment_method_details": {
    "card": {
      "brand": "mastercard",
      "checks": {
        "address_line1_check": null,
        "address_postal_code_check": null,
        "cvc_check": null
      },
      "country": "US",
      "exp_month": 11,
      "exp_year": 2023,
      "fingerprint": "mF8TiHPLLuXUU78G",
      "funding": "credit",
      "installments": null,
      "last4": "4444",
      "mandate": null,
      "network": "mastercard",
      "three_d_secure": null,
      "wallet": null
    },
    "type": "card"
  },
  "receipt_email": null,
  "receipt_number": null,
  "receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xTTlVI6LdMHlXekxkKKzgn...",
  "refunded": false,
  "review": null,
  "shipping": null,
  "source": {
    "id": "card_mFuXUU78G8TiHPLL",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "MasterCard",
    "country": "US",
    "customer": null,
    "cvc_check": null,
    "dynamic_last4": null,
    "exp_month": 11,
    "exp_year": 2023,
    "fingerprint": "U8GUm7LF8TLuiHPX",
    "funding": "credit",
    "last4": "4444",
    "metadata": {
    },
    "name": null,
    "tokenization_method": null
  },
  "source_transfer": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "status": "succeeded",
  "transfer_data": null,
  "transfer_group": null
}

Exemplo utilizando parâmetro $arr_settings na macro sc_call_api

$apiKey = 'YOU_API_KEY';

$arr_settings = array('settings' => ['gateway' => 'stripe', 'apiKey'=> $apiKey] );

$gateway = sc_call_api('', $arr_settings);    
   	 
$response = $gateway->customers->all(['limit' => 5]);

echo "<pre>";
print_r($response);