### Run Cargo Install Command Source: https://builtwithcargo.dev/docs/installation After installing Cargo via Composer, run this Artisan command to publish stubs, set up product collections, and complete the installation process. ```bash php please cargo:install ``` -------------------------------- ### Run Cargo Installation and Migration Commands Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce After installing Cargo via Composer, these Artisan commands are used to publish Cargo's stubs, configure settings like product collections, and migrate existing data from Simple Commerce. ```bash php please cargo:install php please cargo:install ``` -------------------------------- ### Install Cargo using Composer Source: https://builtwithcargo.dev/docs/installation This command installs the Cargo addon for Statamic using Composer. Ensure you have Composer installed and configured for your project. ```bash composer require duncanmcclean/statamic-cargo ``` -------------------------------- ### Stripe CLI for Local Webhook Listening (Bash) Source: https://builtwithcargo.dev/docs/payment-gateways Command to forward Stripe events to a local development environment using the Stripe CLI. This is essential for testing webhook functionality during development. Ensure the Stripe CLI is installed and configured. ```bash stripe listen --forward-to https://your-store.test/!/cargo/payments/stripe/webhook --skip-verify ``` -------------------------------- ### Manage Carts with Cart Facade (PHP) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Demonstrates how to use the Cart facade in PHP to find, query, and create new carts. It shows examples of finding a cart by ID, querying carts by customer, and making/saving a new cart instance. ```PHP use DuncanMcClean\Cargo\Facades\Cart; // Find a cart Cart::find(123); // Query carts by customer Cart::query() ->where('customer','user-id') ->get(); // Make and save a Cart instance Cart::make() ->orderNumber(1234) ->save(); ``` -------------------------------- ### Install and Update Cargo with Composer Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This snippet shows the Composer commands to remove the old Simple Commerce package and install the new Cargo package. It's the first step in upgrading your Statamic e-commerce site. ```bash composer remove duncanmcclean/simple-commerce composer require duncanmcclean/cargo composer remove duncanmcclean/simple-commerce composer require duncanmcclean/cargo ``` -------------------------------- ### Initialize Stripe Payment Form Source: https://builtwithcargo.dev/docs/payment-gateways Initializes the Stripe payment form with customer and billing details. It fetches a payment intent and mounts the Stripe Payment Element to the specified DOM element. This setup is crucial for collecting payment information securely. ```javascript const stripe = Stripe("{{$api_key}}"); let elements; initialize(); document .querySelector("#payment-form") .addEventListener("submit", handleSubmit); async function initialize() { elements = stripe.elements({clientSecret:'{{$client_secret}}'}); const paymentElementOptions = { layout: "accordion", defaultValues: { billingDetails: { name: '{{Statamic::tag('cart:customer:name')}}', email: '{{Statamic::tag('cart:customer:email')}}', address: { line1: '{{Statamic::tag('cart:billing_line_1')}}', line2: '{{Statamic::tag('cart:billing_line_2')}}', city: '{{Statamic::tag('cart:billing_city')}}', postal_code: '{{Statamic::tag('cart:billing_postcode')}}', state: '{{Statamic::tag('cart:billing_state:code')}}', country: '{{{{Statamic::tag('cart:billing_country:iso2')}}}}', }, }, }, }; const paymentElement = elements.create("payment", paymentElementOptions); paymentElement.mount("#payment-element"); } ``` -------------------------------- ### Configure Cargo Payment Gateways (PHP) Source: https://builtwithcargo.dev/docs/payment-gateways This PHP code snippet shows how to configure payment gateways in Cargo by defining them in the `config/statamic/cargo.php` file. It includes examples for a 'dummy' gateway and commented-out examples for 'stripe' and 'mollie', illustrating where to place API keys and other sensitive information. ```php // config/statamic/cargo.php 'payments'=>[ 'gateways'=>[ 'dummy'=>[ // ], // 'stripe' => [ // 'key' => env('STRIPE_KEY'), // 'secret' => env('STRIPE_SECRET'), // 'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'), // ], // 'mollie' => [ // 'api_key' => env('MOLLIE_KEY'), // 'profile_id' => env('MOLLIE_PROFILE_ID'), // ], ], ], // config/statamic/cargo.php 'payments' => [ 'gateways' => [ 'dummy' => [ // ], // 'stripe' => [ // 'key' => env('STRIPE_KEY'), // 'secret' => env('STRIPE_SECRET'), // 'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'), // ], // 'mollie' => [ // 'api_key' => env('MOLLIE_KEY'), // 'profile_id' => env('MOLLIE_PROFILE_ID'), // ], ], ], ``` -------------------------------- ### Custom Payment Gateway Implementation (PHP) Source: https://builtwithcargo.dev/docs/payment-gateways This PHP code defines a custom payment gateway class, `FooPay`, extending Cargo's `PaymentGateway`. It includes methods for setup, processing, capturing, canceling, handling webhooks, and refunds, providing a structure for integrating new payment providers. ```PHP set('amount_refunded', $amount)->save(); } } ``` -------------------------------- ### Stripe Payment Elements Initialization and Submission (JavaScript) Source: https://builtwithcargo.dev/docs/payment-gateways Initializes Stripe's Payment Elements for a customizable payment form and handles form submission to confirm payments. It requires Stripe's JavaScript library and a client secret from your Stripe setup. The code includes UI helpers for displaying messages and managing loading states. ```javascript const stripe = Stripe("{{ $api_key }}"); let elements; initialize(); document .querySelector("#payment-form") .addEventListener("submit", handleSubmit); // Fetches a payment intent and captures the client secret async function initialize() { elements = stripe.elements({ clientSecret: '{{ $client_secret }}' }); const paymentElementOptions = { layout: "accordion", defaultValues: { billingDetails: { name: '{{ Statamic::tag('cart:customer:name') }}', email: '{{ Statamic::tag('cart:customer:email') }}', address: { line1: '{{ Statamic::tag('cart:billing_line_1') }}', line2: '{{ Statamic::tag('cart:billing_line_2') }}', city: '{{ Statamic::tag('cart:billing_city') }}', postal_code: '{{ Statamic::tag('cart:billing_postcode') }}', state: '{{ Statamic::tag('cart:billing_state:code') }}', country: '{{ {{ Statamic::tag('cart:billing_country:iso2') }} }}', }, }, }, }; const paymentElement = elements.create("payment", paymentElementOptions); paymentElement.mount("#payment-element"); } async function handleSubmit(e) { e.preventDefault(); setLoading(true); const { error } = await stripe.confirmPayment({ elements, confirmParams: { // Make sure to change this to your payment completion page return_url: "{{ $checkout_url }}", }, }); // This point will only be reached if there is an immediate error when // confirming the payment. Otherwise, your customer will be redirected to // your `return_url`. For some payment methods like iDEAL, your customer will // be redirected to an intermediate site first to authorize the payment, then // redirected to the `return_url`. if (error.type === "card_error" || error.type === "validation_error") { showMessage(error.message); } else { showMessage("An unexpected error occurred."); } setLoading(false); } // ------- UI helpers ------- function showMessage(messageText) { const messageContainer = document.querySelector("#payment-message"); messageContainer.classList.remove("hidden"); messageContainer.textContent = messageText; setTimeout(function () { messageContainer.classList.add("hidden"); messageContainer.textContent = ""; }, 4000); } function setLoading(isLoading) { document.getElementById('submit').disabled = isLoading; } ``` -------------------------------- ### Cargo JSON API: Get Available Payment Gateways Source: https://builtwithcargo.dev/frontend/json-api/endpoints Returns available payment gateways for the cart, including setup data. Payment gateways are returned even for zero-total carts, though setup data may be absent. ```JSON GET /!/cargo/cart/payment-gateways ``` -------------------------------- ### Install Tailwind CSS Forms Plugin Source: https://builtwithcargo.dev/frontend/checkout/prebuilt Instructions for installing the `@tailwindcss/forms` plugin using npm, which is necessary for customizing form styles with Tailwind CSS. ```bash npm install @tailwindcss/forms ``` -------------------------------- ### PHP: Query All Orders Source: https://builtwithcargo.dev/extending/php-apis/orders Shows how to query all orders in the store using the Cargo PHP Order facade's `query()` method. Examples include filtering orders by site and customer ID, and retrieving the results using `get()`. ```php use DuncanMcClean\Cargo\Facades\Order; Order::query() ->where('site', 'english') ->where('customer', $userId) ->get(); ``` -------------------------------- ### Migrate Simple Commerce Gateway and Shipping Tags to Cargo Antlers Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This guide shows the updated tags for payment gateways and shipping methods in Cargo's Antlers templating. ```antlers {{ sc:gateway }} -> {{ payment_gateways }} {{ sc:gateway:count }} -> {{ payment_gateways | count }} {{ sc:gateway:* }} -> Removed {{ sc:shipping:methods }} -> {{ shipping_methods }} ``` -------------------------------- ### Configure Dummy Payment Gateway (PHP) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This PHP code snippet illustrates how to configure the 'dummy' payment gateway in the `config/statamic/cargo.php` file. It shows the addition of the dummy gateway to the `payments.gateways` array. ```PHP // config/statamic/cargo.php 'payments' => [ 'gateways' => [ 'dummy' => [], ], ], ``` -------------------------------- ### Dummy Payment Gateway Form (Blade) Source: https://builtwithcargo.dev/docs/payment-gateways This Blade template code provides a payment form for the Dummy gateway in Cargo. It mirrors the Antlers example with fields for cardholder name, card number, expiry, and CVC, submitting to the checkout URL. It uses Blade syntax and PHP functions for dynamic content. ```blade
``` -------------------------------- ### Cargo Orders Tag - Blade Example Source: https://builtwithcargo.dev/frontend/tags/orders Provides an example of using the 'orders' tag within a Blade template to display order history. It utilizes Statamic's syntax for accessing the current user and order details, showing the order number, date, and grand total. ```Blade

Order History

Order History

``` -------------------------------- ### Mollie Checkout Link (Blade) Source: https://builtwithcargo.dev/docs/payment-gateways Generates a checkout link for Mollie payments using Blade templating. This link directs the customer to Mollie's website to complete the transaction. ```blade Checkout with Mollie ``` -------------------------------- ### Register Custom Payment Gateway Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Register a custom payment gateway by adding an entry to the `payment.gateways` array in `config/statamic/cargo.php`. The key is the gateway's handle, and you can include any necessary configuration options. ```PHP // config/statamic/cargo.php 'payments' => [ 'gateways' => [ 'custom_payment_gateway' => [ // Any config options... ], ], ], ``` -------------------------------- ### Associate Customer with Order (PHP) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Shows how to associate an order with a customer in PHP. This can be done by passing a User object or ID for registered users, or an array with 'name' and 'email' for guest customers. ```PHP $order->customer($user); $order->customer($user->id()); $order->customer([ 'name'=>'David Hasselhoff', 'email'=>'david@hasselhoff.com', ]); ``` -------------------------------- ### Debugging with Dump Tag in Cargo Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This note explains the usage of the `{{ dump }}` tag in Cargo for debugging purposes, allowing developers to inspect variables within the current view context. ```antlers The `{{ dump }}` tag is an easy way of debugging data inside the current view context (eg. seeing which variables are defined at the current point in time). ``` -------------------------------- ### Uninstall Runway (Bash) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Provides the Composer command to remove the Runway package from a project in a bash environment. This is a post-migration cleanup step if Runway is no longer needed. ```Bash composer remove statamic-rad-pack/runway ``` -------------------------------- ### Handle DiscountCreated Event in PHP Source: https://builtwithcargo.dev/extending/events/list This example demonstrates how to handle the DiscountCreated event, dispatched when a new discount is generated. It provides access to the created discount object. ```PHP public function handle(DiscountCreated $event) { $event->discount; } ``` -------------------------------- ### Migrate Simple Commerce Localization and Error Tags to Cargo Antlers Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This snippet covers the migration of tags related to countries, regions, and error handling in Cargo's Antlers templating. ```antlers {{ sc:countries }} -> {{ dictionary:countries }} {{ sc:regions }} -> {{ states }} {{ sc:errors }} -> {{ get_errors:all }} {{ sc:has_errors }} / {{ sc:hasErrors }} -> {{ {get_errors:all | count} > 0 }} ``` -------------------------------- ### Stripe UI Helper Functions Source: https://builtwithcargo.dev/docs/payment-gateways Includes utility functions for managing the user interface during the payment process. `showMessage` displays feedback messages to the user, and `setLoading` enables or disables the submit button based on the loading state. ```javascript // ------- UI helpers ------- function showMessage(messageText) { const messageContainer = document.querySelector("#payment-message"); messageContainer.classList.remove("hidden"); messageContainer.textContent = messageText; setTimeout(function () { messageContainer.classList.add("hidden"); messageContainer.textContent = ""; }, 4000); } function setLoading(isLoading) { document.getElementById('submit').disabled = isLoading; } ``` -------------------------------- ### Purge Abandoned Carts Command Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Cargo automatically adds a `purge-abandoned-carts` command to your `routes/console.php` during installation. This command is used to clean up abandoned carts. If you were using Simple Commerce's `sc:purge-cart-orders`, it should be removed. ```PHP // routes/console.php // Cargo's purge-abandoned-carts command is registered here. ``` -------------------------------- ### Migrate Simple Commerce Coupon Tags to Cargo Antlers Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This section details the changes for handling coupons in Cargo's Antlers templating, including how to redeem and remove discount codes. ```antlers {{ sc:coupon }} -> Removed {{ sc:coupon:has }} -> {{ if {cart:discount_code} }} {{ sc:coupon:redeem }} -> antlers
{{ cart:update }}

{{ /cart:update }}
{{ sc:coupon:remove }} -> antlers
{{ cart:update }}

{{ /cart:update }}
{{ sc:coupon:* }} -> Removed ``` -------------------------------- ### Create Custom Payment Gateway (PHP) Source: https://builtwithcargo.dev/docs/payment-gateways This command generates a new payment gateway class file in the `app/PaymentMethods` directory. This serves as a template for creating custom payment processing logic within the Cargo system. ```Shell php please make:payment-gateway FooPay ``` -------------------------------- ### Stripe Payment Form Initialization and Submission (JavaScript) Source: https://builtwithcargo.dev/docs/payment-gateways This JavaScript code initializes the Stripe API with a client secret, creates and mounts the Payment Element, and handles form submission. It includes functions to display messages and manage loading states, ensuring a smooth payment process. ```JavaScript // This is a public sample test API key. // Don’t submit any personally identifiable information in requests made with this key. // Sign in to see your own test API key embedded in code samples. const stripe = Stripe("{{ api_key }}"); let elements; initialize(); document .querySelector("#payment-form") .addEventListener("submit", handleSubmit); // Fetches a payment intent and captures the client secret async function initialize() { elements = stripe.elements({ clientSecret: '{{ client_secret }}' }); const paymentElementOptions = { layout: "accordion", defaultValues: { billingDetails: { name: '{{ cart:customer:name }}', email: '{{ cart:customer:email }}', address: { line1: '{{ cart:billing_line_1 }}', line2: '{{ cart:billing_line_2 }}', city: '{{ cart:billing_city }}', postal_code: '{{ cart:billing_postcode }}', state: '{{ cart:billing_state:code }}', country: '{{ cart:billing_country:iso2 }}', }, }, }, }; const paymentElement = elements.create("payment", paymentElementOptions); paymentElement.mount("#payment-element"); } async function handleSubmit(e) { e.preventDefault(); setLoading(true); const { error } = await stripe.confirmPayment({ elements, confirmParams: { // Make sure to change this to your payment completion page return_url: "{{ checkout_url }}", }, }); // This point will only be reached if there is an immediate error when // confirming the payment. Otherwise, your customer will be redirected to // your `return_url`. For some payment methods like iDEAL, your customer will // be redirected to an intermediate site first to authorize the payment, then // redirected to the `return_url`. if (error.type === "card_error" || error.type === "validation_error") { showMessage(error.message); } else { showMessage("An unexpected error occurred."); } setLoading(false); } // ------- UI helpers ------- function showMessage(messageText) { const messageContainer = document.querySelector("#payment-message"); messageContainer.classList.remove("hidden"); messageContainer.textContent = messageText; setTimeout(function() { messageContainer.classList.add("hidden"); messageContainer.textContent = ""; }, 4000); } function setLoading(isLoading) { document.getElementById('submit').disabled = isLoading; } ``` -------------------------------- ### Get Payment Gateway Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get the selected payment gateway. Returns a PaymentGateway object. ```PHP paymentGateway() ``` -------------------------------- ### Get Shipping Option Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get the selected shipping option. Returns a ShippingOption object. ```PHP shippingOption() ``` -------------------------------- ### Get Shipping Method Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get the selected shipping method. Returns a ShippingMethod object. ```PHP shippingMethod() ``` -------------------------------- ### Migrate Cargo Data Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This command initiates the data migration process for Cargo, transferring configurations, customer data, discounts, taxes, orders, and carts from Simple Commerce. It can be run multiple times safely. ```bash php please cargo:migrate php please cargo:migrate ``` -------------------------------- ### Configure Multiple Product Collections in Cargo Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This configuration snippet shows how to specify multiple Statamic collections for products within the `config/statamic/cargo.php` file, enabling better organization of different product types. ```php // config/statamic/cargo.php 'products'=>[ 'collections'=>['courses','merch'], ], // config/statamic/cargo.php 'products' => [ 'collections' => ['courses', 'merch'], ] ``` -------------------------------- ### Configure Shipping Methods in Cargo Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This snippet shows how to configure shipping methods, including free shipping, within the `cargo.php` configuration file after migrating to Cargo. It demonstrates the structure for defining various shipping methods. ```php // config/statamic/cargo.php 'shipping' => [ 'methods' => [ 'free_shipping' => [], ], ], ``` -------------------------------- ### Enable Digital Products in Cargo Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Configure Cargo to enable digital product functionality by setting the 'digital_products' option to true in the Cargo configuration file. This allows specifying downloads for digital products, which become available after an order is completed. ```PHP // config/statamic/cargo.php 'digital_products'=>true, ``` ```PHP // config/statamic/cargo.php 'digital_products' => true, ``` -------------------------------- ### Contributing Translations JSON Example Source: https://builtwithcargo.dev/knowledge-base/translations An example of a JSON file used for contributing translations to Cargo. It shows the format for mapping English text to translated text. ```JSON { "Orders":"**Bestellungen**" } ``` ```JSON { "Orders": "**Bestellungen**" } ``` -------------------------------- ### Apply Discount Code to Cart (PHP) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Demonstrates how to apply a discount code to a cart in PHP using the `->set('discount_code', ...)` method. This replaces the older `->coupon()` and `->redeemCoupon()` methods and must be done before checkout. ```PHP $cart->set('discount_code','BLACKFRIDAY')->save(); ``` -------------------------------- ### Cargo PHP APIs: Introduction and Usage Source: https://builtwithcargo.dev/extending/php-apis/introduction This section introduces Cargo's PHP APIs, explaining how to interact with the system using custom code. It details available methods for managing carts, orders, products, and events. ```PHP cart->get(); print_r($cart); // Add an item to the cart $addItemResult = $cargoClient->cart->add(['product_id' => 1, 'quantity' => 2]); var_dump($addItemResult); // Get order details $order = $cargoClient->orders->get(123); print_r($order); // Listen for an event (conceptual example) $cargoClient->events->listen('order.created', function($eventData) { // Process order creation event error_log('Order created: ' . print_r($eventData, true)); }); ?> ``` -------------------------------- ### Stripe Payment Form HTML Structure Source: https://builtwithcargo.dev/docs/payment-gateways Provides the HTML structure for the Stripe payment form. It includes a container for the Stripe Payment Element, a submit button, and a message container for displaying feedback to the user. The Stripe.js library is also included. ```html
``` -------------------------------- ### Migrate Specific Cargo Data Types Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Provides individual commands to migrate specific data types for Cargo, allowing for granular control over the migration process. This is useful if you need to re-run a specific migration. ```bash php please cargo:migrate:configs php please cargo:migrate:customers php please cargo:migrate:discounts php please cargo:migrate:taxes php please cargo:migrate:orders php please cargo:migrate:carts php please cargo:migrate:products ``` -------------------------------- ### Get Billing Address Source: https://builtwithcargo.dev/extending/php-apis/orders Returns the billing address as an Address object. ```PHP billingAddress() ``` -------------------------------- ### Initialize Custom Payment Gateway Form Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Initialize a custom payment gateway's form using JavaScript. The `init` method takes an object with a `return_url` property, which should be set to the checkout URL provided by Cargo. ```JavaScript
``` -------------------------------- ### Get Shipping Address Source: https://builtwithcargo.dev/extending/php-apis/orders Returns the shipping address as an Address object. ```PHP shippingAddress() ``` -------------------------------- ### Add Custom Checkout Step (Antlers) Source: https://builtwithcargo.dev/frontend/checkout/prebuilt Demonstrates how to add a new step to the checkout process using Antlers partials. It shows how to wrap the step content within the `partial:checkout/step` tag and include input fields and buttons using other partials like `partial:checkout/input` and `partial:checkout/button`. ```html {{ partial:checkout/step title="Gift" }}

If this is a gift, let us know the name of the recipient and we can include a special gift note with the order.

{{ partial:checkout/input name="gift_recipient" label="Gift Recipient" type="text" placeholder="John" }}
{{ slot:footer }} {{ partial:checkout/button label="Continue to Payment" }} {{ /slot:footer }} {{ /partial:checkout/step }} ``` -------------------------------- ### Get Fresh Order Instance Source: https://builtwithcargo.dev/extending/php-apis/orders Returns a fresh instance of the current order. ```PHP fresh() ``` -------------------------------- ### Migrate Customers using Cargo CLI Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Manually migrate existing customers from Simple Commerce to Cargo using the `php please cargo:migrate:customers` command. This command is part of Cargo's migration process and is recommended even if customers were stored as users, as it cleans up old data structures. ```Shell php please cargo:migrate:customers ``` -------------------------------- ### Get Billing Address Source: https://builtwithcargo.dev/extending/php-apis/carts Returns the billing address associated with the cart as an Address object. ```PHP billingAddress() ``` -------------------------------- ### Get Shipping Address Source: https://builtwithcargo.dev/extending/php-apis/carts Returns the shipping address associated with the cart as an Address object. ```PHP shippingAddress() ``` -------------------------------- ### Mollie Checkout Link (Antlers) Source: https://builtwithcargo.dev/docs/payment-gateways Generates a checkout link for Mollie payments using Antlers templating. This link directs the customer to Mollie's website to complete the transaction. ```antlers Checkout with Mollie ``` -------------------------------- ### Get/Set Order Date Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the order date. The `$date` parameter is optional. ```PHP date($date) ``` -------------------------------- ### Migrate Orders using Cargo CLI Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Manually migrate existing orders from Simple Commerce to Cargo using the `php please cargo:migrate:orders` command. This command is part of Cargo's migration process and can be run independently if needed. ```Shell php please cargo:migrate:orders ``` -------------------------------- ### Get/Set Order Number Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the order number. The `$orderNumber` parameter is optional. ```PHP orderNumber($orderNumber) ``` -------------------------------- ### Get/Set Site Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to get or set the site associated with the cart. The `$site` parameter is optional. ```PHP site($site) ``` -------------------------------- ### Get/Set Coupon Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to get or set the coupon applied to the cart. The `$coupon` parameter is optional. ```PHP coupon($coupon) ``` -------------------------------- ### Get/Set Shipping Total Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the shipping total, in pence. The `$shippingTotal` parameter is optional. ```PHP shippingTotal($shippingTotal) ``` -------------------------------- ### Get Tax Breakdown Source: https://builtwithcargo.dev/extending/php-apis/orders Returns a Collection breaking down the taxes applied to line items and shipping options. ```PHP taxBreakdown() ``` -------------------------------- ### Register Custom Payment Gateway (PHP) Source: https://builtwithcargo.dev/docs/payment-gateways This PHP code snippet demonstrates how to register a custom payment gateway, `FooPay`, within the application's service provider. This ensures that Cargo recognizes and can utilize the newly created payment gateway. ```PHP // app/Providers/AppServiceProvider.php use App\PaymentGateways\FooPay; public function boot(): void { FooPay::register(); } ``` -------------------------------- ### Handle Stripe Payment Submission Source: https://builtwithcargo.dev/docs/payment-gateways Handles the submission of the Stripe payment form. It prevents the default form submission, sets a loading state, confirms the payment using Stripe's API, and handles potential errors or redirects the user upon successful payment. ```javascript async function handleSubmit(e) { e.preventDefault(); setLoading(true); const {error} = await stripe.confirmPayment({ elements, confirmParams: { // Make sure to change this to your payment completion page return_url: "{{$checkout_url}}", }, }); // This point will only be reached if there is an immediate error when // confirming the payment. Otherwise, your customer will be redirected to // your `return_url`. For some payment methods like iDEAL, your customer will // be redirected to an intermediate site first to authorize the payment, then // redirected to the `return_url`. if (error.type === "card_error" || error.type === "validation_error") { showMessage(error.message); } else { showMessage("An unexpected error occurred."); } setLoading(false); } ``` -------------------------------- ### Get/Set Tax Total Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the tax total, in pence. The `$taxTotal` parameter is optional. ```PHP taxTotal($taxTotal) ``` -------------------------------- ### Stripe Webhook Secret Configuration (.env) Source: https://builtwithcargo.dev/docs/payment-gateways Stores the Stripe webhook secret in the .env file for enhanced security. This secret is used to verify that incoming webhook requests originate from Stripe. ```bash STRIPE_WEBHOOK_SECRET=whsec_... ``` -------------------------------- ### Get/Set Discount Total Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the discount total, in pence. The `$discountTotal` parameter is optional. ```PHP discountTotal($discountTotal) ``` -------------------------------- ### Track Downloads with ProductDownloaded Event Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Listen to the ProductDownloaded event to track download history, including timestamps and IP addresses, for digital products. This involves updating the order's line items with download details. This is useful if Cargo's default download tracking is insufficient. ```PHP // app/Providers/AppServiceProvider.php Event::listen(ProductDownloaded::class,function($event){ $event->order->lineItems()->update($event->lineItem->id(),[ 'download_history'=>[ ...$event->lineItem->get('download_history',[]), [ 'timestamp'=>now()->toIso8601String(), 'ip_address'=>request()->ip(), ], ]); $event->order->save(); }); ``` ```PHP // app/Providers/AppServiceProvider.php Event::listen(ProductDownloaded::class, function ($event) { $event->order->lineItems()->update($event->lineItem->id(), [ 'download_history' => [ ...$event->lineItem->get('download_history', []), [ 'timestamp' => now()->toIso8601String(), 'ip_address' => request()->ip(), ], ], ]); $event->order->save(); }); ``` -------------------------------- ### Get/Set Sub Total Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the sub total, in pence. The `$subTotal` parameter is optional. ```PHP subTotal($subTotal) ``` -------------------------------- ### Display Payment Gateways in Checkout (Twig) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This snippet demonstrates how to loop through available payment gateways in Cargo's checkout process using Twig. It displays each gateway's name and includes a partial for its payment form, conditionally opening the first gateway's details. ```Twig {{ payment_gateways }}
{{ name }}
{{ partial src="checkout/payment-forms/{handle}" }}
{{ /payment_gateways }} ``` -------------------------------- ### Get/Set Grand Total Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the grand total, in pence. The `$grandTotal` parameter is optional. ```PHP grandTotal($grandTotal) ``` -------------------------------- ### Get/Set Order Site Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the order's site. The `$site` parameter is optional. ```PHP site($site) ``` -------------------------------- ### Migrate Carts using Cargo CLI Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Manually migrate existing carts from Simple Commerce to Cargo using the `php please cargo:migrate:carts` command. This command is part of Cargo's migration process and can be run independently if needed. ```Shell php please cargo:migrate:carts ``` -------------------------------- ### Get/Set Order Coupon Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the order's coupon. The `$coupon` parameter is optional. ```PHP coupon($coupon) ``` -------------------------------- ### Handle Free Cart Checkout (Twig) Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce This code snippet shows how to handle the checkout process when the cart total is zero. It displays a message indicating no payment is required and provides a button to proceed to checkout using a generic checkout URL. ```Twig {{ if {cart:is_free} }}

{{ 'No payment required. Continue to checkout.'|trans }}

{{ /if }} ``` -------------------------------- ### Get/Set Order ID Source: https://builtwithcargo.dev/extending/php-apis/orders Allows you to get or set the order's ID. The `$id` parameter is optional. ```PHP id($id) ``` -------------------------------- ### Get/Set Subtotal Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to get or set the subtotal of the cart, specified in pence. The `$subTotal` parameter is optional. ```PHP subTotal($subTotal) ``` -------------------------------- ### Stripe Payment Form (Antlers/Blade) Source: https://builtwithcargo.dev/docs/payment-gateways This snippet shows the HTML structure for a Stripe payment form, including the Payment Element container and a submit button. It's designed to be used within Antlers or Blade templating engines, with placeholders for API keys and customer data. ```Antlers {{# You should really load this in your if possible. #}}
``` ```Blade
``` -------------------------------- ### Get Fresh Cart Instance Source: https://builtwithcargo.dev/extending/php-apis/carts Returns a fresh instance of the current cart, effectively reloading its state. ```PHP fresh() ``` -------------------------------- ### Publish Pre-built Checkout Flow (PHP) Source: https://builtwithcargo.dev/frontend/checkout/prebuilt This command publishes the pre-built checkout flow assets to your project. It uses the `vendor:publish` Artisan command with a specific tag for the checkout flow. ```PHP php artisan vendor:publish --tag=cargo-prebuilt-checkout ``` -------------------------------- ### Get Payment Gateway Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to retrieve the selected payment gateway for the cart. Returns a PaymentGateway object. ```PHP paymentGateway() ``` -------------------------------- ### Get Shipping Option Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to retrieve the selected shipping option for the cart. Returns a ShippingOption object. ```PHP shippingOption() ``` -------------------------------- ### Dummy Payment Gateway Form (Antlers) Source: https://builtwithcargo.dev/docs/payment-gateways This Antlers template code demonstrates a payment form for the Dummy gateway in Cargo. It includes fields for cardholder name, card number, expiry, and CVC, and submits the data to the checkout URL. The form utilizes Antlers tags for dynamic data retrieval and manipulation. ```antlers
``` -------------------------------- ### Get Shipping Method Source: https://builtwithcargo.dev/extending/php-apis/carts Allows you to retrieve the selected shipping method for the cart. Returns a ShippingMethod object. ```PHP shippingMethod() ``` -------------------------------- ### Configure Mollie Payment Gateway Source: https://builtwithcargo.dev/docs/migrating-from-simple-commerce Manually update the `payment.gateways` array in `config/statamic/cargo.php` to include Mollie configuration. This requires setting the Mollie API key and profile ID using environment variables. ```PHP // config/statamic/cargo.php 'payments' => [ 'gateways' => [ 'mollie' => [ 'api_key' => env('MOLLIE_KEY'), 'profile_id' => env('MOLLIE_PROFILE_ID'), ], ], ], ```