For securely saving credit card information and facilitating future payments, PayPal offers the Vault feature. The Payment Tokens API is part of the Vault and is suitable for your use case. Here's a general outline of how you can use the Payment Tokens API: 1. **Store a Credit Card in the Vault:** - Use the `vault/payment-tokens` API to store the credit card information securely in the Vault. - This will return a payment token that you can associate with your customer or save for future use. 2. **Use the Token for Future Payments:** - When your customer returns to make a payment, retrieve the stored payment token. - Use the token in the `purchase_units` section of your API call to create an order or capture payment. 3. **Payment Token Lifespan:** - While there isn't a specific documentation mentioning the lifespan of payment tokens, they are generally intended for long-term use. It's more likely that the issue you faced might be related to the cards themselves rather than the tokens. 4. **Automatic Payments for Invoices:** - If you want to facilitate automatic payments for invoices, you can schedule your system to initiate payments using the stored payment token associated with the customer. 5. **Additional Considerations:** - Ensure that you comply with PCI DSS requirements when handling credit card information. - Consider tokenizing the credit card information on your server before sending it to PayPal to minimize security risks. Here's a basic example using the PayPal REST API in Javascript: ```javascript // 1. Store Credit Card in the Vault const createToken = async () => { const response = await fetch('https://api.sandbox.paypal.com/v2/vault/payment-tokens', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer YOUR_ACCESS_TOKEN`, }, body: JSON.stringify({ card: { number: '4111111111111111', expiration_date[Removed. Phone #s not permitted], }, }), }); const { id } = await response.json(); // 'id' is the payment token, associate it with your customer or save it for future use console.log(id); }; // 2. Use Token for Future Payments const makePayment = async (paymentToken) => { const response = await fetch('https://api.sandbox.paypal.com/v2/checkout/orders', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer YOUR_ACCESS_TOKEN`, }, body: JSON.stringify({ purchase_units: [{ amount: { currency_code: 'USD', value: '100.00', }, }], payment_source: { token: { id: paymentToken, }, }, }), }); const { id } = await response.json(); // 'id' is the order ID for the payment console.log(id); }; // Example Usage createToken(); // Save the returned payment token and use it later for payments // makePayment('YOUR_SAVED_PAYMENT_TOKEN'); ``` Make sure to replace `'YOUR_ACCESS_TOKEN'` and `'YOUR_SAVED_PAYMENT_TOKEN'` with your actual access token and payment token, respectively. Always consult the latest PayPal API documentation for any updates or changes in API usage.
... View more