Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Alipay Mini Program Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

  1. Install and inspect first. Run 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.
  2. Where to look first. Look for the client/service class that wraps the Alipay OpenAPI (typically something like 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.
  3. First use case. The canonical Alipay mini-program flow: take the 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.

Implementation Patterns

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.

Gotchas and Tips

  • This is a Symfony bundle in a Laravel world. The single most common integration failure will be assuming auto-discovery works. Check 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.
  • Key format is the classic trap. Alipay private keys come as PKCS#1 (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 mismatch. Alipay supports RSA and RSA2; RSA2 is required for most current APIs. Verify the configured sign_type matches what your keypair was generated for — a mismatch produces opaque invalid-signature errors.
  • Sandbox vs production gateway. Confirm which gateway URL the config default points to. Pointing production keys at the sandbox (or vice versa) yields confusing auth failures that look like key problems.
  • Character encoding. Alipay signs the URL-encoded, sorted parameter string. If the bundle constructs the sign string itself, you generally trust it — but if you extend it or build requests manually, sort keys with ksort() and use UTF-8 without BOM. This is where most "works in Postman, fails in PHP" bugs live.
  • Response envelope handling. Every Alipay response nests business data under <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.
  • Debugging opaque errors. Enable HTTP request/response logging (mask keys) in non-production. Alipay error codes like 40004 (business failure) carry a sub_code / sub_msg that actually explains the problem; surface those instead of the top-level msg.
  • Extension point. If the bundle's client is 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.
  • No 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core