Skip to content

Modular logistics and supply chain operating system (LSOS)

ci(api-contract): seed a test-mode Stripe gateway for checkout and top-up

Ronald A. Richardsonbf59370b6af2
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.yml
index 02147135..bf5ecc65 100644
--- a/.github/actions/postman-contract/action.yml
+++ b/.github/actions/postman-contract/action.yml
@@ -72,6 +72,19 @@ inputs:
::add-mask:: for the same secrets.
required: false
default: 'true'
+ stripe-publishable-key:
+ description: >-
+ Stripe TEST publishable key (pk_test_). Seeded into the storefront and ledger
+ gateway rows so the checkout and top-up paths are reachable.
+ required: false
+ default: ''
+ stripe-secret-key:
+ description: >-
+ Stripe TEST secret key (sk_test_). When empty no gateway is seeded and the
+ gateway-backed requests report the gateway as unconfigured, which is the
+ correct result for a fork without the org secrets.
+ required: false
+ default: ''
postman-ref:
description: Ref of the fleetbase/postman repo to check out.
required: false
@@ -111,8 +124,15 @@ runs:
DRIVER_IDENTITY: ${{ inputs.driver-identity }}
DRIVER_PASSWORD: ${{ inputs.driver-password }}
DRIVER_PHONE: ${{ inputs.driver-phone }}
+ STRIPE_PUBLISHABLE_KEY: ${{ inputs.stripe-publishable-key }}
+ STRIPE_SECRET_KEY: ${{ inputs.stripe-secret-key }}
run: |
set -uo pipefail
+ # Masked before it is ever passed on: the seed echoes gateway ids, and --verbose
+ # captures request and response bodies into the uploaded artifact.
+ if [[ -n "${STRIPE_SECRET_KEY:-}" ]]; then
+ echo "::add-mask::${STRIPE_SECRET_KEY}"
+ fi
# Run the mint snippet via `tinker --execute="eval(base64_decode(...))"`.
# Piping a file with a <?php tag to tinker triggers a PsySH parse error, and
# inlining the code would let the shell expand its $variables — base64+eval
@@ -130,6 +150,8 @@ runs:
-e "CI_DRIVER_IDENTITY=${DRIVER_IDENTITY}" \
-e "CI_DRIVER_PHONE=${DRIVER_PHONE}" \
-e "CI_DRIVER_PASSWORD=${DRIVER_PASSWORD}" \
+ -e "CI_STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}" \
+ -e "CI_STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}" \
application php artisan tinker --execute="eval(base64_decode('${CODE}'));" 2>&1 || true)"
KEY="$(printf '%s\n' "$OUT" | grep -oE 'flb_(live|test)_[A-Za-z0-9_-]+' | tail -1 || true)"
PLATFORM_TOKEN="$(printf '%s\n' "$OUT" | grep -oE 'flb_platform_[A-Za-z0-9]+' | tail -1 || true)"
@@ -426,6 +448,7 @@ runs:
sed -i -E \
-e 's/(Authorization:[[:space:]]*Bearer[[:space:]]*)[A-Za-z0-9._-]+/\1<redacted>/gi' \
-e 's/(flb_(live|test|platform)_)[A-Za-z0-9_-]+/\1<redacted>/g' \
+ -e 's/((sk|rk|pk)_(live|test)_)[A-Za-z0-9]+/\1<redacted>/g' \
"$f"
done
diff --git a/.github/workflows/api-contract.yml b/.github/workflows/api-contract.yml
index d283dd2f..6c6a8c83 100644
--- a/.github/workflows/api-contract.yml
+++ b/.github/workflows/api-contract.yml
@@ -313,6 +313,10 @@ jobs:
postman-ref: ${{ inputs.postman-ref }}
postman-api-key: ${{ secrets.POSTMAN_API_KEY }}
github-token: ${{ secrets._GITHUB_AUTH_TOKEN }}
+ # TEST-mode keys only. The live pair also exists in the org secrets and must
+ # never be referenced here — a contract run creates payment intents.
+ stripe-publishable-key: ${{ secrets.STRIPE_TEST_KEY }}
+ stripe-secret-key: ${{ secrets.STRIPE_TEST_SECRET }}
- name: Dump logs on failure
if: failure()
diff --git a/scripts/ci/mint-api-key.php b/scripts/ci/mint-api-key.php
index e9db32ce..976c639b 100644
--- a/scripts/ci/mint-api-key.php
+++ b/scripts/ci/mint-api-key.php
@@ -244,6 +244,82 @@ try {
echo 'SEEDED_DRIVER_IDENTITY=' . $driverIdentity . PHP_EOL;
echo 'SEEDED_DRIVER_PHONE=' . $driverPhone . PHP_EOL;
+ /* ============================================================
+ | STRIPE TEST GATEWAY (Storefront checkout + Ledger top-up)
+ * ============================================================ */
+
+ // Stripe is configured by a Gateway ROW, not by env vars: Storefront resolves it with
+ // Storefront::findGateway('stripe') scoped to the store, then reads
+ // $gateway->config->secret_key. With no row the checkout chain answers
+ // "Stripe not setup." and the ledger top-up answers "No query results for Gateway".
+ //
+ // Both values come from the CI environment and are TEST-mode by contract — the action
+ // passes STRIPE_TEST_KEY / STRIPE_TEST_SECRET. Nothing is seeded when the secret is
+ // absent, so a fork without the org secrets still runs everything else.
+ $stripePublishable = getenv('CI_STRIPE_PUBLISHABLE_KEY') ?: '';
+ $stripeSecret = getenv('CI_STRIPE_SECRET_KEY') ?: '';
+
+ if ($stripeSecret && isset($store) && class_exists(\Fleetbase\Storefront\Models\Gateway::class)) {
+ $storefrontGateway = \Fleetbase\Storefront\Models\Gateway::withoutGlobalScopes()
+ ->where(['owner_uuid' => $store->uuid, 'code' => 'stripe'])
+ ->first();
+
+ if (!$storefrontGateway) {
+ $storefrontGateway = new \Fleetbase\Storefront\Models\Gateway();
+ $storefrontGateway->company_uuid = $company->uuid;
+ $storefrontGateway->owner_uuid = $store->uuid;
+ // Assigned through the mutator, which runs Utils::getMutationType() — every
+ // other writer in the package sets it this way, and storing the FQCN directly
+ // produces a value findGateway's owner scoping will not match.
+ $storefrontGateway->owner_type = 'storefront:store';
+ $storefrontGateway->code = 'stripe';
+ $storefrontGateway->type = 'stripe';
+ }
+
+ $storefrontGateway->created_by_uuid = $user->uuid;
+ $storefrontGateway->name = 'CI Contract Stripe (test mode)';
+ $storefrontGateway->sandbox = true;
+ $storefrontGateway->config = [
+ 'public_key' => $stripePublishable,
+ 'secret_key' => $stripeSecret,
+ ];
+ $storefrontGateway->save();
+
+ echo 'SEEDED_STOREFRONT_GATEWAY=' . $storefrontGateway->fresh()->public_id . PHP_EOL;
+ }
+
+ if ($stripeSecret && class_exists(\Fleetbase\Ledger\Models\Gateway::class)) {
+ // A different model with a different shape: keyed by `driver` rather than `code`,
+ // and its Stripe driver reads `publishable_key` where Storefront reads
+ // `public_key`. Seeding one does not seed the other.
+ $ledgerGateway = \Fleetbase\Ledger\Models\Gateway::withoutGlobalScopes()
+ ->where(['company_uuid' => $company->uuid, 'driver' => 'stripe'])
+ ->first();
+
+ if (!$ledgerGateway) {
+ $ledgerGateway = new \Fleetbase\Ledger\Models\Gateway();
+ $ledgerGateway->company_uuid = $company->uuid;
+ $ledgerGateway->driver = 'stripe';
+ }
+
+ $ledgerGateway->created_by_uuid = $user->uuid;
+ $ledgerGateway->name = 'CI Contract Stripe (test mode)';
+ $ledgerGateway->is_sandbox = true;
+ $ledgerGateway->environment = 'sandbox';
+ $ledgerGateway->status = 'active';
+ $ledgerGateway->config = [
+ 'publishable_key' => $stripePublishable,
+ 'secret_key' => $stripeSecret,
+ ];
+ $ledgerGateway->save();
+
+ echo 'SEEDED_LEDGER_GATEWAY=' . $ledgerGateway->fresh()->public_id . PHP_EOL;
+ }
+
+ if (!$stripeSecret) {
+ echo '::notice::No Stripe test secret provided; gateway-backed requests will report the gateway as unconfigured.' . PHP_EOL;
+ }
+
/* ============================================================
| LEDGER INVOICE FIXTURE (Fleetbase Ledger API / Public Invoices)
* ============================================================ */