Auto-replenish
When the Alipay+ NFC SDK notices that the credentials number falls below a certain threshold (the default threshold is 10), it automatically calls the replenish() API to fetch new credentials from the server.
Note: In most cases, the SDK automatically manages the cache of payment credentials, requiring no intervention from your app. However, as the MPP, you can trigger this process manually by calling the replenish() API.
Workflow
The following figure illustrates the auto-replenish workflow:

The auto-replenish process consists of the following steps:
- After the user makes an NFC tap, the Alipay+ NFC SDK processes a payment flow. (Steps 1-3)
- Upon completion of the payment processing, the SDK automatically checks the local credential number.
- If the local credential number falls below the auto-replenish threshold, the following steps are executed. (Step 4)
- The SDK initiates a request session with the Ant server. (Steps 5-12)
- The SDK requests new credentials from the server. (Steps 13-20)
- The SDK securely stores the payment credentials locally. (Step 21)
Step 1: Process general payment
After each NFC tapping, the Alipay+ NFC SDK checks the number of local payment credentials. If the number of local payment credentials falls below a certain threshold, the SDK automatically requests additional credentials from Mastercard. If the local credential number does not fall below the auto-replenish threshold, no further action will be taken.
Step 2: Request payment credentials
Note: All requests from the Alipay+ NFC SDK to the Ant server side are proxied by the NFCRequestProxy SPI. For more information, see Proxy SDK requests.
When the number of local payment credentials falls below a certain threshold, the SDK first builds a request session with Mastercard.
Then the SDK sends the replenish request to the Ant server to fetch credentials. The Ant server then requests credentials from Mastercard. After obtaining the credentials, the Ant server returns the credentials to the SDK. The SDK securely stores the credentials.