Base URL: https://api.vornify.se/api/vornifypay

1. One-Time Payment

POST /api/vornifypay

Create a one-time payment for products or services.

Request Format:

{
    "command": "payment",
    "data": {
        "amount": 149.99,
        "currency": "usd",
        "payment_type": "onetime",
        "product_data": {
            "name": "Product Name",
            "product_id": "PROD_123",
            "description": "Product Description",
            "customer_name": "John Doe",
            "email": "customer@example.com",
            "phone": "+1234567890",
            // Additional product details as needed
        }
    }
}

Response Format:

{
    "status": true,
    "payment_intent_id": "pi_xxxxxxxxxxxxx",
    "client_secret": "pi_xxxxxxxxxxxxx_secret_xxxxxxxxxxxxx",
    "public_key": "pk_xxxxxxxxxxxxxxxxxxxxxxxx",
    "amount": 149.99,
    "currency": "usd",
    "payment_type": "onetime",
    "product_details": {
        // Product data echoed back
    }
}

2. Subscription Payment (Two-Step Process)

Step 1: Create Subscription

POST /api/vornifypay

Request Format:

{
    "command": "create_subscription",
    "data": {
        "customer_email": "customer@example.com",
        "amount": "499.00",
        "currency": "sek",
        "trial_days": 7,
        "billing_interval": "month",  // "month" or "year"
        "product_data": {
            "name": "Premium Plan",
            "description": "Premium Monthly Subscription",
            "customer_name": "John Doe",
            "features": ["Feature 1", "Feature 2"],
            "metadata": {
                "plan_level": "premium"
            }
        }
    }
}

Response Format:

{
    "status": true,
    "subscription_id": "sub_xxxxxxxxxxxxx",
    "client_secret": "pi_xxxxxxxxxxxxx_secret_xxxxxxxxxxxxx",
    "public_key": "pk_xxxxxxxxxxxxxxxxxxxxxxxx",
    "subscription_details": {
        "amount": "499.00",
        "currency": "sek",
        "trial_end": "2024-03-24T00:00:00Z",
        "billing_interval": "month",
        "product_name": "Premium Plan",
        "customer_email": "customer@example.com",
        "status": "incomplete"
    }
}

Frontend Implementation

After receiving the response, implement the payment form in your frontend:

// 1. Add Stripe.js to your HTML
<script src="https://js.stripe.com/v3/"></script>

// 2. Create payment form in HTML
<form id="payment-form">
    <div id="card-element"></div>
    <button type="submit">Subscribe</button>
</form>

// 3. Initialize Stripe and handle payment
const initializePayment = (response) => {
    const stripe = Stripe(response.public_key);
    const elements = stripe.elements();
    const card = elements.create('card');
    card.mount('#card-element');

    const form = document.getElementById('payment-form');
    form.addEventListener('submit', async (event) => {
        event.preventDefault();
        
        const { error, paymentIntent } = await stripe.confirmCardPayment(
            response.client_secret,
            {
                payment_method: {
                    card: card,
                    billing_details: {
                        email: 'customer@example.com',
                        name: 'John Doe'
                    }
                }
            }
        );

        if (error) {
            console.error('Payment failed:', error);
        } else {
            console.log('Subscription activated:', paymentIntent);
            // Handle successful subscription
        }
    });
};

Complete Example

// Backend (Node.js)
app.post('/create-subscription', async (req, res) => {
    const subscriptionData = {
        command: 'create_subscription',
        data: {
            customer_email: 'customer@example.com',
            amount: '499.00',
            currency: 'sek',
            trial_days: 7,
            billing_interval: 'month',
            product_data: {
                name: 'Premium Plan',
                description: 'Premium Monthly Subscription',
                customer_name: 'John Doe',
                features: ['Feature 1', 'Feature 2']
            }
        }
    };

    const response = await fetch('https://api.vornify.se/api/vornifypay', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(subscriptionData)
    });

    const result = await response.json();
    res.json(result);
});

// Frontend (JavaScript)
async function startSubscription() {
    try {
        // 1. Create subscription
        const response = await fetch('/create-subscription');
        const result = await response.json();

        if (!result.status) {
            throw new Error(result.error);
        }

        // 2. Initialize Stripe payment form
        const stripe = Stripe(result.public_key);
        const elements = stripe.elements();
        const card = elements.create('card');
        card.mount('#card-element');

        // 3. Handle form submission
        const form = document.getElementById('payment-form');
        form.addEventListener('submit', async (e) => {
            e.preventDefault();
            const { error, paymentIntent } = await stripe.confirmCardPayment(
                result.client_secret,
                {
                    payment_method: {
                        card: card,
                        billing_details: {
                            email: 'customer@example.com',
                            name: 'John Doe'
                        }
                    }
                }
            );

            if (error) {
                // Handle error
                console.error('Payment failed:', error);
            } else {
                // Handle success
                console.log('Subscription active:', paymentIntent);
                // Redirect to success page or update UI
            }
        });
    } catch (error) {
        console.error('Error:', error);
    }
}

Important Notes:

Testing:

Use these test card numbers:

3. Verify Payment

POST /api/vornifypay

Verify the status of a payment.

Request Format:

{
    "command": "verify",
    "data": {
        "payment_intent_id": "pi_xxxxxxxxxxxxx"
    }
}

Response Format:

{
    "status": true,
    "payment_status": "succeeded",
    "amount": 149.99,
    "currency": "usd",
    "metadata": {
        // Payment metadata
    }
}

Client-Side Integration

1. Initialize Stripe:

const stripe = Stripe('YOUR_PUBLIC_KEY');
const elements = stripe.elements();

2. Create Payment Form:

// Create card element
const card = elements.create('card');
card.mount('#card-element');

// Handle form submission
async function handlePayment(clientSecret) {
    const result = await stripe.confirmCardPayment(clientSecret, {
        payment_method: {
            card: card,
            billing_details: {
                name: 'Customer Name',
                email: 'customer@example.com'
            }
        }
    });

    if (result.error) {
        // Handle error
        console.error(result.error);
    } else {
        // Payment successful
        console.log(result.paymentIntent);
    }
}

3. Handle Subscription:

async function handleSubscription(clientSecret) {
    const result = await stripe.confirmCardPayment(clientSecret, {
        payment_method: {
            card: card,
            billing_details: {
                name: 'Customer Name',
                email: 'customer@example.com'
            }
        },
        setup_future_usage: 'off_session'
    });

    if (result.error) {
        // Handle error
        console.error(result.error);
    } else {
        // Subscription successful
        console.log(result.paymentIntent);
    }
}

Important Notes: