a
    ]f
                     @   sB   d dl Z d dlZd dlmZmZ d dlZd dlZG dd dZdS )    N)datetime	timedeltac                   @   s4   e Zd Zedejej fddZed	ddZdS )
BigCommerceService   c                    s   d  fddt| D S )N c                 3   s   | ]}t  V  qd S )N)secretschoice).0_chars KC:\storyit\storyit_web\backend\services\integrations\bigcommerce_service.py	<genexpr>       z:BigCommerceService.generate_random_code.<locals>.<genexpr>)joinrange)sizer   r   r   r   generate_random_code	   s    z'BigCommerceService.generate_random_coder      c              
   C   s   d|  d}||dd}	t  t|d }
|
d}t }d| d |d	krRd
nd|||d|ddgddd	}tj||	|d}td|j	 |j	dkrtd nH|j
rz| }td| W q tjy   td|j Y q0 ntd td| |S )Nz#https://api.bigcommerce.com/stores/z/v2/couponszapplication/json)zX-Auth-TokenzX-Auth-ClientzContent-Type)daysz%a, %d %b %Y %H:%M:%S +0000z	StoryIt: z (Do not edit)CashZper_total_discountZpercentage_discountT
categoriesr   )entityids   )	nametypeamountZmin_purchaseexpiresenabledcode
applies_toZmax_uses)headersjsonzStatus Code:i  z=Conflict detected: A coupon with this code may already exist.zResponse Body:z)Failed to decode JSON, raw response text:zNo response body was received.zGenerated Coupon Code:)r   nowr   strftimer   r   requestspostprintstatus_codecontentr$   JSONDecodeErrortext)Z
store_pathZ
auth_tokenZauth_client
offer_nameZpercent_or_cash_offcompensationmin_purchase_amountZexpiration_daysurlr#   Zexpiration_dateZformatted_expiration_dateZcoupon_codedataresponseresponse_datar   r   r   create_single_use_discount_code   sF    




z2BigCommerceService.create_single_use_discount_codeN)r   r   )	__name__
__module____qualname__staticmethodstringascii_lettersdigitsr   r5   r   r   r   r   r      s     r   )r   r:   r   r   r'   r$   r   r   r   r   r   <module>   s
   