useLoyalty
Integrations

Shopify Integration

Award points for Shopify orders and create discount rewards

Connect your Shopify store to automatically award points for purchases, handle refunds, and generate discount codes as rewards.

Features

  • Points for Purchases: Automatic points based on order value
  • Refund Handling: Proportional point deduction on refunds
  • Discount Codes: Generate unique coupon codes as rewards
  • Product Multipliers: Bonus points for specific products/collections
  • Guest Exclusion: Option to exclude guest checkout
  • Multiplier Events: Double/triple points during promotions

Setup

1. Connect Your Store

  1. Navigate to SettingsIntegrationsShopify
  2. Click Connect Shopify Store
  3. Enter your shop domain (e.g., mystore.myshopify.com)
  4. Authorize the app in Shopify

2. OAuth Permissions

The app requests these permissions:

ScopePurpose
read_ordersProcess orders for points
write_ordersUpdate order metadata
read_customersIdentify customers
write_customersCreate customer records
read_productsProduct multipliers
write_discountsGenerate reward coupons
read_price_rulesDiscount management
write_price_rulesCreate price rules

3. Configure Points Settings

SettingDefaultDescription
Points per Dollar1Points earned per $1 spent
Rounding ModeFLOORHow to round points (FLOOR, CEIL, ROUND)
Min Order AmountNoneMinimum order to earn points
Exclude ShippingYesDon't count shipping in points
Exclude TaxYesDon't count tax in points
Exclude GuestYesRequire customer account

Webhook Events

The integration automatically registers these webhooks:

EventAction
orders/paidAward points to customer
orders/cancelledRefund all points
refunds/createProportional point refund
customers/createCreate member record
customers/updateUpdate member info
app/uninstalledDeactivate connection

Points Calculation

Formula

Eligible Amount = Subtotal [- Shipping] [- Tax]
Points = Eligible Amount × Points per Dollar × Multiplier

Example

Order Total: $150.00
Shipping: $10.00
Tax: $12.00
Points per Dollar: 1

Eligible Amount = $150 - $10 - $12 = $128
Points Earned = 128 × 1 = 128 points

With Multiplier Event

Base Points: 128
Active Multiplier: 2x ("Double Points Weekend")
Final Points: 128 × 2 = 256 points

Product Multipliers

Set higher earning rates for specific products:

By Product

{
  "productOverrides": {
    "gid://shopify/Product/12345": {
      "multiplier": 2.0
    },
    "gid://shopify/Product/67890": {
      "multiplier": 1.5
    }
  }
}

By Collection

{
  "collectionOverrides": {
    "gid://shopify/Collection/premium": {
      "multiplier": 2.0
    },
    "gid://shopify/Collection/sale": {
      "multiplier": 0.5
    }
  }
}

Priority Order

  1. Product-specific multiplier (highest priority)
  2. Collection multiplier (if multiple, use highest)
  3. Default multiplier (1.0)

Refund Handling

Full Cancellation

When an order is cancelled:

  • All points earned from the order are refunded
  • Transaction status set to REFUNDED

Partial Refund

Points are refunded proportionally:

Refund Ratio = Refund Amount / Original Order Total
Points Refunded = Original Points × Refund Ratio

Example:

Original Order: $100 → 100 points earned
Refund Amount: $30
Refund Ratio: 30 / 100 = 0.30
Points Refunded: 100 × 0.30 = 30 points
Remaining Points: 70 points

Discount Code Rewards

Create rewards that generate Shopify discount codes:

Percentage Discount

{
  "name": "10% Off Reward",
  "type": "COUPON",
  "pointsCost": 500,
  "discountConfig": {
    "type": "PERCENTAGE",
    "value": 10
  }
}

Fixed Amount Discount

{
  "name": "$20 Off Reward",
  "type": "COUPON",
  "pointsCost": 1000,
  "discountConfig": {
    "type": "FIXED_AMOUNT",
    "value": 20
  }
}

Free Shipping

{
  "name": "Free Shipping Reward",
  "type": "COUPON",
  "pointsCost": 300,
  "discountConfig": {
    "type": "FREE_SHIPPING"
  }
}

Generated Code Format

USELOYALTY-ABC123XY
  • Prefix: USELOYALTY-
  • Random: 8 characters
  • Usage: 1 per customer, 1 total

API Endpoints

List Stores

GET /api/shopify/stores

Returns all connected Shopify stores with stats.

Get Store Settings

GET /api/shopify/stores/:storeId/settings

Returns points configuration for a store.

Update Settings

PATCH /api/shopify/stores/:storeId/settings
{
  "pointsPerDollar": 2,
  "roundingMode": "FLOOR",
  "excludeShipping": true,
  "excludeTax": true,
  "excludeGuestCheckout": true,
  "minOrderAmount": 25.0,
  "productOverrides": {
    "gid://shopify/Product/123": { "multiplier": 2.0 }
  }
}

Widget Integration

Embed the loyalty widget in your Shopify theme:

1. Get Widget Code

{% if customer %}
<script src="https://cdn.useloyalty.app/widget/useloyalty-widget.iife.js"></script>
<script>
  // Fetch auth from your app proxy
  fetch('/apps/useloyalty/widget-auth')
    .then(r => r.json())
    .then(auth => {
      UseLoyaltyWidget.init({
        ...auth,
        member: {
          email: '{{ customer.email }}',
          name: '{{ customer.name }}'
        }
      });
    });
</script>
{% endif %}

2. App Proxy Setup

Configure Shopify app proxy to route /apps/useloyalty/* to your widget auth endpoint.

Troubleshooting

Points Not Awarded

  1. Check order is paid (not pending)
  2. Verify customer has an account (if guest excluded)
  3. Check minimum order amount
  4. Review webhook delivery in Shopify admin

Webhook Errors

GET /api/shopify/webhooks/logs

Check recent webhook deliveries and errors.

Duplicate Points

The system uses idempotency keys to prevent duplicates:

  • Each order can only award points once
  • Check ShopifyOrderTransaction table for existing record

Data Model

ShopifyStore

{
  id: string;
  projectId: string;
  shopDomain: string;
  shopName: string;
  accessToken: string; // Encrypted
  isActive: boolean;
  connectedAt: Date;
}

ShopifyOrderTransaction

{
  id: string;
  storeId: string;
  memberId: string;
  shopifyOrderId: string;
  orderNumber: string;
  customerEmail: string;
  orderTotal: Decimal;
  eligibleAmount: Decimal;
  pointsEarned: number;
  status: "PENDING" | "PROCESSED" | "REFUNDED" | "PARTIALLY_REFUNDED";
  refundedAmount: Decimal;
  pointsRefunded: number;
}

Best Practices

1. Set Appropriate Points Rate

Low value (1 point = $1): Easy to earn, high redemption
High value (1 point = $10): Harder to earn, lower redemption

2. Use Collection Multipliers

Boost slow-moving inventory:

{
  "clearance-collection": { "multiplier": 2.0 }
}

3. Run Multiplier Events

Create urgency with time-limited bonuses:

"Double Points Weekend" - 2x multiplier, Fri-Sun

4. Test Webhook Delivery

Use Shopify's webhook testing to verify integration:

  1. Go to Settings → Notifications → Webhooks
  2. Click "Send test notification"
  3. Verify receipt in useLoyalty logs

On this page