Skip to main content

Redeeming Points

The redeem method exchanges points for a discount on an order. It is available through the useLoyalty hook and the LoyaltyService.

Usage

import { useLoyalty } from 'react-native-stackfront-sdk';

function RedeemPoints({ customerId, cartTotal }: { customerId: string; cartTotal: number }) {
  const { account, redeem, loading } = useLoyalty(customerId);
  const [pointsToUse, setPointsToUse] = useState('');

  const handleRedeem = async () => {
    try {
      const result = await redeem(Number(pointsToUse), cartTotal);
      Toast.show(`Redeemed ${result.pointsRedeemed} points for $${result.discountAmount}`);
    } catch (err) {
      Toast.show(err.message);
    }
  };

  if (!account) return null;

  return (
    <View>
      <Text>Available: {account.pointsBalance} points</Text>
      <Input
        value={pointsToUse}
        onChangeText={setPointsToUse}
        placeholder="Points to redeem"
        keyboardType="numeric"
      />
      <Button
        title="Redeem"
        onPress={handleRedeem}
        disabled={loading || !pointsToUse}
      />
    </View>
  );
}

Hook API

redeem: (pointsToRedeem: number, orderTotal: number) => Promise<RedeemPointsResponse>

Response Shape

{
  success: boolean;
  pointsRedeemed: number;
  discountAmount: number;
  remainingBalance: number;
  message: string;
}

Service API

const { loyalty } = useStackfront();
const result = await loyalty.redeem({
  customerId: 'customer-id',
  pointsToRedeem: 500,
  orderTotal: 49.99,
});