tourze/alipay-mini-program-bundle
A Symfony bundle from Tourze for integrating Alipay Mini Program support into PHP applications. It provides bundle configuration and service wiring to help connect Symfony projects with Alipay mini-program APIs and related workflows.
This package sits at an unusual intersection: despite being assessed in a Laravel context, tourze/alipay-mini-program-bundle is named and structured as a Symfony bundle. The 0.1.0 release is effectively the first tagged "usable" milestone (it jumped from 0.0.2 with only a changelog entry, no feature list), so treat this as early-adopter territory.
composer require tourze/alipay-mini-program-bundle:^0.1.0, then immediately open vendor/tourze/alipay-mini-program-bundle/ and read the composer.json, the DependencyInjection/ directory, and any *Extension.php / *Bundle.php files. Because it is a bundle rather than a Laravel service provider, you need to confirm whether there is a Laravel adapter, a config/services.php-friendly wrapper, or whether you must register bindings manually.AlipayMiniProgramClient or a *Service under src/). That class defines the actual surface area you'll use day-to-day. Configuration keys (app ID, private key, Alipay public key, sign type, gateway URL) will live in a Configuration.php or an example .yaml/config.php.code returned by the mini-program's login call, exchange it via alipay.system.oauth.token (code2session-equivalent) to obtain user_id/access_token/open_id, then optionally call alipay.user.info.share for profile data. Wire this to a single controller route and confirm the round trip against Alipay's sandbox gateway before touching production credentials.If you are not on Symfony, budget time for a thin bridge (service provider + config file + facade) before you write any feature code — the bundle was not authored with Laravel's container conventions in mind.
Wrap, don't scatter. Register the bundle's client as a singleton in your Laravel container (via a small AlipayMiniProgramServiceProvider if none ships) and inject it into a dedicated AlipayAuthService / AlipayPaymentService. This keeps the third-party class out of your controllers and makes swapping to the official SDK later a one-file change.
Auth-code flow. Treat the mini-program code as single-use and short-lived. Pattern: controller validates input → service calls system.oauth.token → persist or cache user_id + access_token keyed by open_id → respond with your own session token. Never return Alipay's access_token to the client.
Token caching. Access tokens are rate-limited and time-boxed. Implement a cache layer (Cache::remember with a TTL slightly under the returned expires_in) rather than calling the token endpoint per request. This is the single biggest performance and quota win in daily use.
Payment/notify handling. For mini-program payments, follow the pattern: server creates trade (alipay.trade.create) → client invokes my.tradePay with the trade_no → Alipay posts to your notify_url. Your notify handler must verify the signature with the Alipay public key before trusting any field, then return the literal string success. Put verification in a reusable middleware or form request so every notify route is protected.
Testing seam. Because the client wraps HTTP calls, bind an interface plus a fake in your test suite. Sandbox credentials + Http::fake()-style stubbing (if the bundle uses PSR-18/HttpClient under the hood) lets you test the whole flow without network calls. Write one integration test against sandbox for the happy path, and unit tests for signature verification and error mapping.
Config as environment. Keep app_id, private key, and public key in .env, never committed. If the bundle expects a YAML config (Symfony convention), generate that file from env vars in your service provider rather than hand-maintaining two sources of truth.
composer.json for a symfony/laravel extra block that registers the bundle. If absent, manual provider registration is required — and config merging behavior will differ from what Laravel devs expect.0.1.0 with a bare changelog is a yellow flag. No documented feature set, no upgrade guide from 0.0.2. Pin the exact version (0.1.0, not ^0.1) and watch the repo for 0.2.0 breaking changes. Semantic versioning below 1.0.0 permits breaking changes in minor bumps.BEGIN RSA PRIVATE KEY) while many PHP libraries expect PKCS#8 (BEGIN PRIVATE KEY). If you get signature errors on the first call, convert with openssl pkcs8 -topk8 -nocrypt before blaming the package. Likewise, public keys must be the raw key, not wrapped in -----BEGIN PUBLIC KEY----- headers if the bundle strips/expects them — read the source to confirm.sign_type matches what your keypair was generated for — a mismatch produces opaque invalid-signature errors.ksort() and use UTF-8 without BOM. This is where most "works in Postman, fails in PHP" bugs live.<method>_response plus a sign field. Confirm whether the bundle unwraps this or returns the raw envelope — if it returns raw, your service layer should normalize it once, not in every caller.40004 (business failure) carry a sub_code / sub_msg that actually explains the problem; surface those instead of the top-level msg.final or its methods private, you cannot subclass cleanly. Prefer decoration (a wrapper class implementing your own interface) over inheritance — this also protects you if 0.2.0 renames internals.Http::fake guarantee. If the bundle uses a specific Symfony HttpClient adapter rather than Laravel's, test doubles need to target that adapter. Read composer.json for symfony/http-client vs guzzlehttp/guzzle to know which mocking approach applies.How can I help you explore Laravel packages today?