Conn2Flow
Docs navigation

Reference / Libraries

stripe.php library

REST client for the Stripe API: gateway credentials, customers, payments, subscriptions, product and price catalog, refunds and webhook validation.

Path in the Gestor bibliotecas/stripe.php

Direct calls to the Stripe REST API (api.stripe.com) with cURL, without the official SDK. The API version is pinned in STRIPE_API_VERSION (2024-06-20), so the response format does not change with the account settings.

Credentials

The normal path is a stripe-type record of the gateways_pagamentos table (registered in the gateways module):

Column Use
client_id Publishable key (pk_…)
client_secret Secret key (sk_…)
webhook_secret Webhook signing secret (whsec_…)
ambiente P = production; any other value = sandbox
moeda Default BRL
gestor_incluir_biblioteca('stripe');
stripe_gateways_pagamentos_configurar();            // the default gateway (padrao='S') or the first active one
stripe_gateways_pagamentos_configurar(['id' => 7]); // a specific gateway

The configuration goes into $_CONFIG['stripe'], which can also be filled by hand. stripe_obter_credenciais() returns false without a secret_key; stripe_info() summarizes the state; stripe_testar_conexao() calls GET /v1/balance. stripe_is_modo_gateway(), stripe_obter_gateway_id() and stripe_obter_gateway_dados() tell which gateway was loaded.

Request

stripe_requisicao(['endpoint' => '/v1/…', 'method' => 'GET'|'POST'|'DELETE', 'data' => [...], 'idempotency_key' => …]) returns ['http_code', 'data'] or false (no credentials or network error). An API error (4xx/5xx) is not false: check http_code. Errors go to gestor/logs/stripe-<date>.log through log.php, without the key.

Amounts: stripe_valor_menor_unidade(19.9, 'BRL') → 1990; stripe_valor_decimal() does the opposite; stripe_moeda_sem_decimais() covers JPY, KRW, VND, CLP and PYG.

Operations

Area Functions
Customers stripe_obter_ou_criar_cliente(['email', 'nome', 'metadata']): looks up by e-mail before creating
One-off payment stripe_criar_payment_intent(), stripe_consultar_payment_intent(), stripe_consultar_setup_intent()
Subscriptions stripe_criar_assinatura() (born default_incomplete, returning the first invoice's client_secret, or trialing with trial_period_days; coupon_id applies a Stripe coupon through discounts; add_invoice_items adds products and shipping to the first invoice), stripe_consultar_assinatura() (optional expand), stripe_definir_metodo_padrao_assinatura(), stripe_trocar_preco_assinatura() (upgrade/downgrade with proration, default always_invoice; body built by stripe_troca_preco_payload()), stripe_suspender_assinatura() (pause_collection), stripe_ativar_assinatura() (undoes a pause or a scheduled cancellation), stripe_cancelar_assinatura()
Refund stripe_reembolsar()
Catalog stripe_criar_produto(), stripe_atualizar_produto() (partial merge; body built by stripe_produto_payload()), stripe_consultar_produto(), stripe_listar_produtos(), stripe_arquivar_produto(); stripe_criar_preco(), stripe_consultar_preco(), stripe_listar_precos(), stripe_arquivar_preco() (a price is immutable in Stripe: changing the amount means creating another)
Support stripe_traduzir_status() (status → Portuguese text), stripe_log_registro()

Webhook

stripe_validar_webhook(['payload' => $rawBody, 'signature_header' => $header, 'tolerancia' => 300]) checks the Stripe-Signature header (HMAC-SHA256 of t.payload with the webhook_secret, constant-time comparison, 300 s window) and returns the decoded event or false.

The endpoint is /_gateways/stripe/webhook (the plataforma-gateways controller), which validates with the default gateway and fires the stripe.webhook hook.

Functions

Generated from gestor/bibliotecas/stripe.php · 37 functions

37 of 37

stripe_gateways_pagamentos_configurar

view source · line 31 ↗
stripe_gateways_pagamentos_configurar(array|false $params = false): bool

Configura a biblioteca a partir de um registro da tabela gateways_pagamentos.

Parameters

$paramsarray|false
['id' => id do gateway] ou vazio para o gateway padrão do tipo stripe.

Returns

bool

stripe_requisicao

view source · line 134 ↗
stripe_requisicao(array|false $params = false): array|false

Requisição HTTP à API do Stripe.

Parameters

$paramsarray|false

Returns

array|false
['http_code' => int, 'data' => array] ou false

stripe_obter_ou_criar_cliente

view source · line 230 ↗
stripe_obter_ou_criar_cliente(array $params = Array()): array|false

Localiza um cliente pelo e-mail ou cria um novo. Evita duplicar customers a cada checkout.

Parameters

$paramsarray
['email' => string, 'nome' => string opcional, 'metadata' => array opcional]

Returns

array|false
Dados do customer ou false.

stripe_criar_payment_intent

view source · line 265 ↗
stripe_criar_payment_intent(array $params = Array()): array|false

Cria um PaymentIntent para pagamento único no Payment Element.

Parameters

$paramsarray
['valor' => decimal, 'moeda' => 'BRL', 'customer_id' => opc,

Returns

array|false
['id','client_secret','status'] ou false.

stripe_criar_assinatura

view source · line 346 ↗
stripe_criar_assinatura(array $params = Array()): array|false

Cria uma assinatura em default_incomplete para confirmação no Payment Element.

Parameters

$paramsarray
['customer_id' => obrig, 'price_id' => obrig, 'referencia' => opc,

Returns

array|false
['id','status','client_secret','secret_type' => 'payment'|'setup','subscription_data'] ou false.

stripe_troca_preco_payload

view source · line 509 ↗
stripe_troca_preco_payload(array $sub, array $params = Array()): array|false

Monta o corpo da troca de preço de uma assinatura, resolvendo trial_end contra a assinatura em curso. Separada da requisição para ser verificável sem rede.

Parameters

$subarray
Assinatura consultada (precisa de items.data[0].id).
$paramsarray
Mesmos parâmetros de stripe_trocar_preco_assinatura.

Returns

array|false
Corpo da requisição ou false quando a assinatura não tem item de preço.

stripe_trocar_preco_assinatura

view source · line 544 ↗
stripe_trocar_preco_assinatura(array $params = Array()): array|false

Troca o preço de uma assinatura ativa (upgrade/downgrade) com proration nativa.

Parameters

$paramsarray
['subscription_id' => obrig, 'price_id' => obrig,

Returns

array|false
Assinatura atualizada ou false.

stripe_reembolsar

view source · line 618 ↗
stripe_reembolsar(array $params = Array()): array|false

Reembolsa um pagamento.

Parameters

$paramsarray
['payment_intent_id' => ou 'charge_id', 'valor' => decimal opc (total se ausente), 'moeda' => opc]

Returns

array|false

stripe_criar_produto

view source · line 644 ↗
stripe_criar_produto(array $params = Array()): array|false

Cria um produto no catálogo (POST /v1/products).

Parameters

$paramsarray
['nome' => obrig, 'descricao' => opc, 'imagens' => array de URLs opc,

Returns

array|false
Produto criado (prod_...) ou false.

stripe_produto_payload

view source · line 676 ↗
stripe_produto_payload(array $params = Array()): array

Monta o corpo de uma atualização de produto.

Parameters

$paramsarray
Mesmos campos de stripe_atualizar_produto.

Returns

array
Corpo pronto para http_build_query.

stripe_atualizar_produto

view source · line 703 ↗
stripe_atualizar_produto(array $params = Array()): array|false

Atualiza um produto existente (POST /v1/products/{id}).

Parameters

$paramsarray
['product_id' => obrig, 'nome' => opc, 'descricao' => opc,

Returns

array|false
Produto atualizado ou false.

stripe_listar_produtos

view source · line 731 ↗
stripe_listar_produtos(array $params = Array()): array|false

Lista produtos da conta (GET /v1/products).

Parameters

$paramsarray
['limite' => 1..100 (padrão 100), 'ativo' => bool opc, 'starting_after' => opc]

Returns

array|false
['data' => array de produtos, 'has_more' => bool] ou false.

stripe_criar_preco

view source · line 763 ↗
stripe_criar_preco(array $params = Array()): array|false

Cria um preço (POST /v1/prices).

Parameters

$paramsarray
['product_id' => obrig, 'valor' => decimal obrig, 'moeda' => 'BRL',

Returns

array|false
Preço criado (price_...) ou false.

stripe_listar_precos

view source · line 812 ↗
stripe_listar_precos(array $params = Array()): array|false

Lista preços da conta (GET /v1/prices).

Parameters

$paramsarray
['product_id' => opc (filtra por produto), 'limite' => 1..100,

Returns

array|false
['data' => array de preços, 'has_more' => bool] ou false.

stripe_validar_webhook

view source · line 849 ↗
stripe_validar_webhook(array $params = Array()): array|false

Valida a assinatura de um webhook (Stripe-Signature) por HMAC-SHA256.

Parameters

$paramsarray
['payload' => corpo cru, 'signature_header' => header, 'tolerancia' => seg (300)]

Returns

array|false
Evento decodificado ou false.

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting