If your checkout flow does not require an additional step after applying a payment method you can provide the complete_checkout property in your request body with a value of true. This will submit your cart as an order and complete the checkout process if the payment method is valid.

POST /checkout/cart/{cart_id}/payment

Apply a payment method to the given cart. API Reference: Apply Payment Method

Request

cart_id

The ID of the cart for which the payment method is being applied to.

Applying a Generated Token

If you are building a client side application we recommend using the Stripe.js library to first tokenize your customers card data before sending it to Violet. You can learn more about how to do this in our Payments and Payouts section. Once you have a generated token you can apply it a cart with a request similar to the following example.

Curl
curl -X POST https://sandbox-api.violet.io/v1/checkout/cart/{cart_id}/payment \
-H "X-Violet-App-Id: your-app-id-here" \
-H "X-Violet-App-Secret: your-app-secret-here" \
-H "X-Violet-Token: your-token-here" \
-H "Content-type: application/json" \
-d '{"token": "tok_1EGsV1K29KDiBVldS5kJLqfX"}'

Applying a Credit/Debit Card If using a generated payment token is not possible for your application and you plan on being PCI compliant you apply card data directly to a cart. The following snippet shows an example of this.

Curl
curl -X POST https://sandbox-api.violet.io/v1/checkout/cart/{cart_id}/payment \
-H "X-Violet-App-Id: your-app-id-here" \
-H "X-Violet-App-Secret: your-app-secret-here" \
-H "X-Violet-Token: your-token-here" \
-H "Content-type: application/json" \
-d '{"card_number": "4242424242424242", "card_cvc": 111, "card_exp_month": 12, "card_exp_year": 2022, "complete_checkout": true}'

Tokens will always take priority over card data when applying the payment method to a cart. If you wish to use card data please leave the token property empty or simply omitted from the request body.

Response

JSON
{
    "id": 20956,
    "token": "c8f17e9e6fec4268bc9188f039ec68ad",
    "user_id": 10397,
    "app_id": 10382,
    "developer_id": 10292,
    "customer": {
        "user_id": 10397,
        "first_name": "Paul",
        "last_name": "Sherman",
        "email": "dorythefish@disney.com",
        "name": "Paul Sherman"
    },
    "bags": [
        {
            "id": 20440,
            "order_id": 20956,
            "merchant_id": 10000,
            "app_id": 10382,
            "status": "IN_PROGRESS",
            "fulfillment_status": "PROCESSING",
            "financial_status": "UNPAID",
            "skus": [
                {
                    "id": 24987,
                    "merchant_id": 10000,
                    "app_id": 10382,
                    "product_id": "0ff55c5cda7447118d6ae1c8395f8f11",
                    "sku_id": 10064,
                    "external_id": "13884047425654",
                    "name": "GoPro - Karma Quadcopter with HERO6 Black - White - White",
                    "brand": "GoPro",
                    "thumbnail": "https://cdn.shopify.com/s/files/1/0057/6467/7750/products/6029300_ra.jpg",
                    "quantity": 1,
                    "price": 84999,
                    "weight": 13.45,
                    "available": true,
                    "status": "IN_PROGRESS",
                    "line_price": 84999
                }
            ],
            "shipping_method": {
                "type": "FLAT_RATE_PRICE",
                "carrier": "OTHER",
                "label": "International Shipping",
                "price": 2000,
                "id": 17032,
                "shipping_method_id": "shopify-International%20Shipping-20.00",
                "bag_id": 20440,
                "merchant_id": 10000
            },
            "taxes": [],
            "sub_total": 84999,
            "transactions": [],
            "external_checkout": true,
            "commission_rate": 15.0,
            "date_created": "2022-05-11T16:17:16+0000",
            "remorse_period_ends": "2022-06-10T16:17:16+0000",
            "currency": "USD",
            "external_currency": "USD",
            "channel": "APP",
            "platform": "SHOPIFY",
            "fulfillments": [],
            "merchant_name": "Violet-Besties"
        }
    ],
    "shipping_address": {
        "city": "Sydney",
        "state": "NSW",
        "country": "AU",
        "postal_code": "2000",
        "type": "SHIPPING",
        "address_1": "42 Wallaby Way"
    },
    "billing_address": {
        "city": "Sydney",
        "state": "NSW",
        "country": "AU",
        "postal_code": "2000",
        "type": "BILLING",
        "address_1": "42 Wallaby Way"
    },
    "payment_method": {
        "brand": "visa",
        "last_four": "4242",
        "exp_month": 12,
        "exp_year": 2025,
        "payment_method_id": 5465
    },
    "sub_total": 84999,
    "status": "IN_PROGRESS",
    "date_created": "2022-05-11T16:17:16+0000",
    "date_last_modified": "2022-05-12T16:28:38+0000",
    "priced": false,
    "currency": "USD",
    "errors": [],
    "channel": "APP",
    "currency_symbol": "$",
    "stripe_key": "pk_test_UHg8oLvg4rrDCbvtqfwTE8qd",
    "guest": true
}

Was this page helpful?