tourze/wechat-mini-program-insurance-freight-bundle
Integrates WeChat Mini Program freight insurance (运费险) into Tourze/Symfony PHP projects. Provides bundle configuration and service wiring for freight-insurance workflows, helping mini program commerce applications connect insurance features with minimal setup.
This release (0.1.1) is a patch on top of 0.1.0 with no documented functional changes — the changelog only links the diff between 0.1.0...0.1.1, so treat it as a maintenance bump rather than a feature release. Since there is no prior assessment, start by verifying what you actually have installed before designing around it.
tourze/*-bundle packages are Symfony-style bundles (a *Bundle class extending Symfony\Component\HttpKernel\Bundle\Bundle), not native Laravel service providers. Check composer.json for extra.laravel.providers / extra.laravel.aliases. If absent, you will need to register the provider (or the bundle's DI config) manually — see Gotchas.src/ and look for the client/service class that talks to WeChat's freight-insurance (运费险) endpoints, plus any DependencyInjection/ configuration tree. The config keys there are your integration surface.app_id, app_secret, and an access-token strategy. Get a sandbox/test mini-program before writing feature code — the API is not mockable in a meaningful way without one.Wrap the client behind your own interface. Do not inject the vendor client directly into controllers or jobs. Define FreightInsuranceGateway with quote(), bind(), cancel(), query() and adapt the package to it. This is the single highest-value pattern here: the WeChat freight-insurance API surface is narrow but has churn, and 0.1.x is pre-1.0.
Token handling in a queued/cached context. Access tokens are per-app and short-lived. Resolve and cache them in a dedicated service (Cache::remember('wechat:token:'.$appId, ...)) and pass them in, rather than letting each call fetch. If the bundle owns token retrieval, decorate it so you can add a distributed lock — concurrent token refresh is the classic failure here.
Bind on order state transitions, not on checkout. Fire bind() from an event listener (OrderPaid, OrderShipped) inside a queued listener with $tries = 3 and exponential backoff. Insurance binding is an external side effect; it must not block the request that created it, and it must not be lost.
Idempotency keys from your own domain. Derive the outbound request identifier from order_id + operation, store it on the order (or a freight_insurance_policies table), and check it before every call. Retries after a timeout should reconcile via query() rather than re-bind().
Model the policy as a first-class record. A freight_insurance_policies table (order_id, policy_no, status, premium, raw_response json, timestamps) means you can retry, audit, and support finance without asking WeChat. Persist the raw response — the package's DTOs will change shape across 0.1.x.
Feature-flag it. Put a FREIGHT_INSURANCE_ENABLED config gate in front of the gateway so staging and local never hit the live API, and so you can disable it during a WeChat outage without a deploy.
extra.laravel block, you must either register the bundle's services manually in a service provider (importing its services.xml/services.yaml) or use symfony/dependency-injection in parallel with the Laravel container — awkward and easy to get wrong. Test container resolution early with a single resolve() smoke test."0.1.1", not "^0.1") and read the diff before every bump. The 0.1.1 changelog gives you nothing to go on beyond the compare link — open that URL and read the actual commits before upgrading.app_id surfaces as an opaque HTTP error several layers down. Add a boot-time check in your own provider that throws on startup if required keys are unset.errcode/errmsg, and the HTTP status at info; log the full payload at debug with secrets scrubbed. WeChat's error codes are numeric and undocumented in the package — build a small map as you encounter them.query() automatically; gate bind() behind your own idempotency record.*-laravel packages; check Packagist before hand-rolling the service provider, and check again at 0.2.x — a provider appearing upstream is the natural moment to delete your glue code.How can I help you explore Laravel packages today?