PayPal Approve Payment API
Finalize and capture PayPal payments after user approval to complete the transaction
PayPal Approve Payment API
Complete the PayPal checkout flow by capturing the payment after user approval. This finalizes the transaction and activates the user's subscription or purchase.
Finalize Payment
Capture the authorized payment to complete the transaction.
Verified Transaction
Payment only captured after PayPal confirms user approval.
Instant Activation
Subscription activated immediately upon successful capture.
Endpoint Overview
/graphqlApprove and capture a PayPal payment using the order ID received after user completes PayPal checkout. Finalizes the transaction and activates the purchase.
Request Parameters
orderIdStringRequiredThe PayPal order ID received from the paypalCreatePayment mutation and confirmed during user checkout.
GraphQL Mutation
mutation paypalApprovePayment($orderId: String) {
paypalApprovePayment(orderId: $orderId) {
success
errorMessage
}
}Variables:
{
"orderId": "5O190127TN364715T"
}HTTP Request:
curl -X POST https://api.orbnet.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"query": "mutation paypalApprovePayment($orderId: String) { paypalApprovePayment(orderId: $orderId) { success errorMessage } }",
"variables": {
"orderId": "5O190127TN364715T"
}
}'Response
{
"data": {
"paypalApprovePayment": {
"success": true,
"errorMessage": null
}
}
}{
"data": {
"paypalApprovePayment": {
"success": false,
"errorMessage": "Order has already been captured"
}
}
}{
"errors": [
{
"message": "Order not found or not approved",
"path": ["paypalApprovePayment"],
"extensions": {
"code": "ORDER_NOT_FOUND"
}
}
],
"data": null
}Complete PayPal Flow
Create Order
Call paypalCreatePayment to create a PayPal order and get orderId.
Redirect to PayPal
User is redirected to PayPal to log in and approve the payment.
User Approves
PayPal redirects user back to your site with approval confirmation.
Capture Payment
Call this API with the orderId to capture the approved payment.
Activate Subscription
On success, the subscription or purchase is automatically activated.
Frontend Integration
paypal.Buttons({
createOrder: async () => {
const response = await fetch('/api/create-paypal-order', {
method: 'POST',
body: JSON.stringify({ groupId: 1, category: 'SUBSCRIPTION' })
});
const data = await response.json();
return data.orderId;
},
onApprove: async (data) => {
// Call this API to capture the payment
const response = await fetch('/api/approve-paypal-order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ orderId: data.orderID })
});
const result = await response.json();
if (result.success) {
// Payment successful - redirect to success page
window.location.href = '/payment-success';
} else {
// Show error message
alert('Payment failed: ' + result.errorMessage);
}
},
onCancel: () => {
// User cancelled - redirect or show message
console.log('Payment cancelled by user');
},
onError: (err) => {
// Handle errors
console.error('PayPal error:', err);
}
}).render('#paypal-button-container');Best Practices
Capture Immediately
Call this API as soon as user returns from PayPal to prevent timeout or abandonment.
Handle Duplicates
Attempting to capture an already-captured order returns an error. Handle gracefully.
Show Loading State
Display a loading indicator while capturing. This step communicates with PayPal servers.
Success Confirmation
Always show clear success message and next steps after successful capture.
Error Handling
ORDER_NOT_FOUND
Order ID doesn't exist or wasn't created by your account.
ORDER_EXPIRED
PayPal orders expire after a period. Create a new order if expired.
ALREADY_CAPTURED
Payment was already captured. Check if subscription is active.
NOT_APPROVED
User hasn't approved the payment yet. Wait for PayPal redirect.
Related Endpoints
Required Step
This API must be called after the user approves payment on PayPal. Without calling this endpoint, the payment will not be captured and the subscription will not be activated.
Complete Your PayPal Integration
Ensure you've implemented both create and approve endpoints for a complete PayPal checkout experience.