Facilitates user registration for a loyalty program via an API endpoint. It checks if the user is already a member of the loyalty program. If so, it returns an error indicating that the user is already a member. It then constructs user data from the request parameters. It then retrieves the default loyalty card associated with the merchant's loyalty program. If no default card exists, it throws a runtime exception. The function attempts to sign up the user for the loyalty program. If the signup process fails due to validation errors, it throws a validation exception.
After a successful signup, the function extracts offer and coupon code information from any freebie items received during signup. It then retrieves the user's loyalty program details and returns a success response containing the user's loyalty program ID, offer details, and coupon code.
