B
    ?F[7                 @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZdgZ	dZ
dd Zd	d
 Zdd Zdd Zdd ZG dd deZdS )    N)AWSQueryConnection)ResponseErrorFactory)ResponseFactoryFPSConnection)actionresponsec             C   s&   x t D ]}t||t| |d  qW |S )N)decorated_attrssetattrgetattr)functoattr r   2lib/python3.7/site-packages/boto/fps/connection.pyadd_attrs_from$   s    
r   c                 s    fdd}|S )Nc                s0    fdd}d  jd|_t |dS )Nc                s^   xLt |j D ]<}||}t|dt|||d < t|d| j||d < qW | f||S )NZValuez.ValueCurrencyCodez.CurrencyCode)filterhas_keypopr
   strcurrencycode)selfargskwZfieldZamount)fieldsr   r   r   wrapper,   s    
z3complex_amounts.<locals>.decorator.<locals>.wrapperz{0}
Complex Amounts: {1}z, )r   )format__doc__joinr   )r   r   )r   )r   r   	decorator+   s    z"complex_amounts.<locals>.decoratorr   )r   r   r   )r   r   complex_amounts*   s    r    c                 s    fdd}|S )Nc                s>    fdd}d dd D }d j||_t |dS )Nc                 sX    fdd}dt t|krNddd D }dtdd	|}t||  S )
Nc                s   t | t t j| kS )N)lenr   r   )x)r   r   r   <lambda>>   s    z>requires.<locals>.decorator.<locals>.wrapper.<locals>.<lambda>   z OR c             S   s   g | ]}d  |qS )+)r   ).0gr   r   r   
<listcomp>@   s    z@requires.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>z{0} requires {1} argument(s)r   ZMethod)r!   r   r   r   r
   KeyError)r   r   Zhasgroupmessage)r   groups)r   r   r   =   s    z,requires.<locals>.decorator.<locals>.wrapperz OR c             S   s   g | ]}d  |qS )r%   )r   )r&   r'   r   r   r   r(   E   s    z/requires.<locals>.decorator.<locals>.<listcomp>z{0}
Required: {1})r   )r   r   r   r   )r   r   r*   )r+   )r   r   r   ;   s
    zrequires.<locals>.decoratorr   )r+   r   r   )r+   r   requires9   s    r,   c                s&    fdd}d  j|_t |dS )Nc                 s   | dt   | |S )NCallerReference)
setdefaultuuidZuuid4)r   r   )r   r   r   r   N   s    z'needs_caller_reference.<locals>.wrapperz2{0}
Uses CallerReference, defaults to uuid.uuid4())r   )r   r   r   )r   r   r   )r   r   needs_caller_referenceL   s    
r0   c                 s    fdd}|S )Nc                s|   d pttjjd t ttj	j
 d rJttj	j
 d  fdd}  |_|_
d j|_|S )N _ZResponsec                s   |  f||S )Nr   )r   r   r   )r   r   r   r   r   r   ^   s    z.api_action.<locals>.decorator.<locals>.wrapperzFPS {0} API call
{1})r   mapr   
capitalize__name__splitr   hasattrbotofpsr   r
   r   r   r   )r   r   )api)r   r   r   r   r   X   s    
zapi_action.<locals>.decoratorr   )r:   r   r   )r:   r   
api_actionV   s    r;   c                   s.  e Zd ZdZeZdZ fddZdd Ze	e
dedd	d
dge dd Zedge dd Zedge dd Zedge dd Ze dd Zedge dd Ze dd Ze dd Ze	edd ge d!d" Ze	ed#d$gd%d& Ze	e
d'ed
d(d)ge d*d+ Ze	e
d'ed
d(d)ge d,d- Zedge d.d/ Ze
d'ed0d(d)ge d1d2 Ze
d3edd4d5d6ge d7d8 Zed9ge d:d; Zed5gd<ge d=d> Zed?d@ge dAdB Ze dCdD Zed<ge dEdF Z ed<ge dGdH Z!e	e
dIeddJd
dKge dLdM Z"edge dNdO Z#e	e
dPeddQdRge dSdT Z$edUge dVdW Z%edUge dXdY Z&e	e
d3edUge dZd[ Z'ed<ge d\d] Z(  Z)S )^r   z
2010-08-28ZUSDc                s2   | d| j| _|dd tt| j|| d S )Nr   hostzfps.sandbox.amazonaws.com)r   r   r.   superr   __init__)r   r   r   )	__class__r   r   r>   m   s    zFPSConnection.__init__c             C   s   dgS )Nr9   r   )r   r   r   r   _required_auth_capabilityr   s    z'FPSConnection._required_auth_capabilityZSettlementAmountZCreditInstrumentIdzSettlementAmount.ValueZSenderTokenIdzSettlementAmount.CurrencyCodec             K   s   |  |||S )z
        Allows a caller to initiate a transaction that atomically transfers
        money from a sender's payment instrument to the recipient, while
        decreasing corresponding debt balance.
        )
get_object)r   r   r   r   r   r   r   settle_debtu   s    zFPSConnection.settle_debtZTransactionIdc             K   s   |  |||S )z:
        Gets the latest status of a transaction.
        )rA   )r   r   r   r   r   r   r   get_transaction_status   s    z$FPSConnection.get_transaction_statusZ	StartDatec             K   s   |  |||S )z>
        Returns transactions for a given date range.
        )rA   )r   r   r   r   r   r   r   get_account_activity   s    z"FPSConnection.get_account_activityc             K   s   |  |||S )z7
        Returns all details of a transaction.
        )rA   )r   r   r   r   r   r   r   get_transaction   s    zFPSConnection.get_transactionc             C   s   |  |i |S )z~
        Returns the total outstanding balance for all the credit instruments
        for the given creditor account.
        )rA   )r   r   r   r   r   r   get_outstanding_debt_balance   s    z*FPSConnection.get_outstanding_debt_balanceZPrepaidInstrumentIdc             K   s   |  |||S )zP
        Returns the balance available on the given prepaid instrument.
        )rA   )r   r   r   r   r   r   r   get_prepaid_balance   s    z!FPSConnection.get_prepaid_balancec             C   s   |  |i |S )z
        Returns the total liability held by the given account corresponding to
        all the prepaid instruments owned by the account.
        )rA   )r   r   r   r   r   r   get_total_prepaid_liability   s    z)FPSConnection.get_total_prepaid_liabilityc             C   s   |  |i |S )zJ
        Returns the account balance for an account in real time.
        )rA   )r   r   r   r   r   r   get_account_balance   s    z!FPSConnection.get_account_balanceZPaymentInstructionZ	TokenTypec             K   s   |  |||S )z<
        Installs a payment instruction for caller.
        )rA   )r   r   r   r   r   r   r   install_payment_instruction   s    z)FPSConnection.install_payment_instructionZ	returnURLpipelineNamec       
         s   d| j krdpd}d|}d}d}|d |ks8td|d	d
d |d| j dd fdd t fdd| D }dd }dd||||g}| j	
|}	|d |	fg7 }|  d||||S )zj
        Generate a signed URL for the Co-Branded service API given arguments as
        payload.
        sandboxzpayments-sandboxZpaymentszauthorize.{0}.amazon.comz/cobranded-ui/actions/start)Z	SingleUseZMultiUseZ	RecurringZ	RecipientZSetupPrepaidZSetupPostpaidZ	EditTokenrK   zInvalid pipelineNameZ
HmacSHA2562)ZsignatureMethodZsignatureVersionZ	callerKeyc             S   s   | d k	rt | pdS )Nr1   )r   )r"   r   r   r   r#      s    z(FPSConnection.cbui_url.<locals>.<lambda>c                s   t j | ddS )N~)Zsafe)urllibZquote)r"   )safestrr   r   r#      s    c                s   g | ]\}}| |fqS r   r   )r&   kv)	safequoter   r   r(      s    z*FPSConnection.cbui_url.<locals>.<listcomp>c             S   s   d dd | D S )N&c             S   s   g | ]\}}|d  | qS )=r   )r&   rQ   rR   r   r   r   r(      s    z<FPSConnection.cbui_url.<locals>.<lambda>.<locals>.<listcomp>)r   )pr   r   r   r#      s    
ZGET	signaturezhttps://{0}{1}?{2})r<   r   AssertionErrorupdater.   Zaws_access_key_idsorteditemsr   Z_auth_handlerZsign_stringsort)
r   r   rL   ZendpointbaseZvalidpipelinesZpayloadZencodedZ	canonicalrX   r   )rS   rP   r   cbui_url   s$    

zFPSConnection.cbui_urlZTransactionAmountzTransactionAmount.ValuezTransactionAmount.CurrencyCodec             K   s   |  |||S )z
        Reserve API is part of the Reserve and Settle API conjunction that
        serve the purpose of a pay where the authorization and settlement have
        a timing difference.
        )rA   )r   r   r   r   r   r   r   reserve   s    zFPSConnection.reservec             K   s   |  |||S )zY
        Allows calling applications to move money from a sender to a recipient.
        )rA   )r   r   r   r   r   r   r   pay   s    	zFPSConnection.payc             K   s   |  |||S )zP
        Cancels an ongoing transaction and puts it in cancelled state.
        )rA   )r   r   r   r   r   r   r   cancel   s    zFPSConnection.cancelZReserveTransactionIdc             K   s   |  |||S )z
        The Settle API is used in conjunction with the Reserve API and is used
        to settle previously reserved transaction.
        )rA   )r   r   r   r   r   r   r   settle  s    	zFPSConnection.settleZRefundAmountzRefundAmount.Valuer-   zRefundAmount.CurrencyCodec             K   s   |  |||S )z=
        Refunds a previously completed transaction.
        )rA   )r   r   r   r   r   r   r   refund  s    zFPSConnection.refundZRecipientTokenIdc             K   s   |  |||S )z/
        Returns the recipient status.
        )rA   )r   r   r   r   r   r   r   !get_recipient_verification_status  s    z/FPSConnection.get_recipient_verification_statusZTokenIdc             K   s   |  |||S )z
        Returns the details of a particular token installed by this calling
        application using the subway co-branded UI.
        )rA   )r   r   r   r   r   r   r   get_token_by_caller  s    z!FPSConnection.get_token_by_callerZUrlEndPointZHttpParametersc             K   s   |  |||S )zM
        Verify the signature that FPS sent in IPN or callback urls.
        )rA   )r   r   r   r   r   r   r   verify_signature(  s    zFPSConnection.verify_signaturec             K   s   |  |||S )zJ
        Returns a list of tokens installed on the given account.
        )rA   )r   r   r   r   r   r   r   
get_tokens0  s    zFPSConnection.get_tokensc             K   s   |  |||S )z/
        Returns the usage of a token.
        )rA   )r   r   r   r   r   r   r   get_token_usage7  s    zFPSConnection.get_token_usagec             K   s   |  |||S )zd
        Cancels any token installed by the calling application on its own
        account.
        )rA   )r   r   r   r   r   r   r   cancel_token?  s    zFPSConnection.cancel_tokenZFundingAmountzFundingAmount.ValuezFundingAmount.CurrencyCodec             K   s   |  |||S )zL
        Funds the prepaid balance on the given prepaid instrument.
        )rA   )r   r   r   r   r   r   r   fund_prepaidH  s    	zFPSConnection.fund_prepaidc             K   s   |  |||S )zS
        Returns the balance corresponding to the given credit instrument.
        )rA   )r   r   r   r   r   r   r   get_debt_balanceS  s    zFPSConnection.get_debt_balanceZAdjustmentAmountzAdjustmentAmount.ValuezAdjustmentAmount.CurrencyCodec             K   s   |  |||S )zu
        Allows a creditor to write off the debt balance accumulated partially
        or fully at any time.
        )rA   )r   r   r   r   r   r   r   write_off_debt[  s    
zFPSConnection.write_off_debtZSubscriptionIdc             K   s   |  |||S )zF
        Returns the transactions for a given subscriptionID.
        )rA   )r   r   r   r   r   r   r   !get_transactions_for_subscriptiong  s    z/FPSConnection.get_transactions_for_subscriptionc             K   s   |  |||S )zQ
        Returns the details of Subscription for a given subscriptionID.
        )rA   )r   r   r   r   r   r   r   get_subscription_detailso  s    z&FPSConnection.get_subscription_detailsc             K   s*   d}d|ksd|kst || |||S )z)
        Cancels a subscription.
        z@If you specify a RefundAmount, you must specify CallerReference.zRefundAmount.Valuer-   )rY   rA   )r   r   r   r   r*   r   r   r   cancel_subscription_and_refundw  s    z,FPSConnection.cancel_subscription_and_refundc             K   s   |  |||S )z:
        Gets the payment instruction of a token.
        )rA   )r   r   r   r   r   r   r   get_payment_instruction  s    z%FPSConnection.get_payment_instruction)*r5   
__module____qualname__Z
APIVersionr   ZResponseErrorr   r>   r@   r0   r    r,   r;   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   __classcell__r   r   )r?   r   r   g   s   	
	
)rO   r/   Zboto.connectionr   Zboto.fps.exceptionr   Zboto.fps.responser   r8   __all__r   r   r    r,   r0   r;   r   r   r   r   r   <module>   s   
