U
    W+d7                     @   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"   t D ]}t||t| |d  q|S N)decorated_attrssetattrgetattr)functoattr r   7/tmp/pip-unpacked-wheel-dlxw5sjy/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                    sZ   t |j D ]<}||}t|dt|||d < t|d| j||d < q| f||S )NValuez.ValueCurrencyCodez.CurrencyCode)filterhas_keypopr   strcurrencycode)selfargskwfield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 r   )lenr   r   xr   r   r   <lambda>>       z>requires.<locals>.decorator.<locals>.wrapper.<locals>.<lambda>    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   groupsr,   r   r   =   s    
 z,requires.<locals>.decorator.<locals>.wrapperr0   c                 S   s   g | ]}d  |qS r1   r3   r4   r   r   r   r7   E   s     z/requires.<locals>.decorator.<locals>.<listcomp>z{0}
Required: {1}r    )r#   r!   r"   r   )r   r   r9   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   needs_caller_referenceL   s
    r@   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 _Responsec                    s   |  f||S r   r   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$   apirE   r   r'   X   s    zapi_action.<locals>.decoratorr   )rN   r'   r   rM   r   
api_actionV   s    rO   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__rD   	__class__r   r   rR   m   s    zFPSConnection.__init__c                 C   s   dgS )NrL   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.
        rV   rX   r   r   r   get_transaction_status   s    z$FPSConnection.get_transaction_statusZ	StartDatec                 K   s   |  |||S )z>
        Returns transactions for a given date range.
        rV   rX   r   r   r   get_account_activity   s    z"FPSConnection.get_account_activityc                 K   s   |  |||S )z7
        Returns all details of a transaction.
        rV   rX   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.
        rV   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.
        rV   rX   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.
        rV   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.
        rV   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.
        rV   rX   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	EditTokenrc   zInvalid pipelineNameZ
HmacSHA2562)ZsignatureMethodZsignatureVersionZ	callerKeyc                 S   s   | d k	rt | pdS )NrA   )r   r*   r   r   r   r-      r.   z(FPSConnection.cbui_url.<locals>.<lambda>c                    s   t j | ddS )N~)safe)urllibquoter*   )safestrr   r   r-      r.   c                    s   g | ]\}}| |fqS r   r   r5   kv)	safequoter   r   r7      s     z*FPSConnection.cbui_url.<locals>.<listcomp>c                 S   s   d dd | D S )N&c                 S   s   g | ]\}}|d  | qS )=r   rk   r   r   r   r7      s     z<FPSConnection.cbui_url.<locals>.<lambda>.<locals>.<listcomp>r3   )pr   r   r   r-      r.   
GET	signaturezhttps://{0}{1}?{2})rP   r!   AssertionErrorupdater>   Zaws_access_key_idsorteditemsr#   Z_auth_handlerZsign_stringsort)
r   r   rd   ZendpointbaseZvalidpipelinespayloadencoded	canonicalrt   r   )rn   rj   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.
        rV   rX   r   r   r   reserve   s    zFPSConnection.reservec                 K   s   |  |||S )zY
        Allows calling applications to move money from a sender to a recipient.
        rV   rX   r   r   r   pay   s    	zFPSConnection.payc                 K   s   |  |||S )zP
        Cancels an ongoing transaction and puts it in cancelled state.
        rV   rX   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.
        rV   rX   r   r   r   settle  s    	zFPSConnection.settleZRefundAmountRefundAmount.Valuer=   zRefundAmount.CurrencyCodec                 K   s   |  |||S )z=
        Refunds a previously completed transaction.
        rV   rX   r   r   r   refund  s    zFPSConnection.refundZRecipientTokenIdc                 K   s   |  |||S )z/
        Returns the recipient status.
        rV   rX   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.
        rV   rX   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.
        rV   rX   r   r   r   verify_signature(  s    zFPSConnection.verify_signaturec                 K   s   |  |||S )zJ
        Returns a list of tokens installed on the given account.
        rV   rX   r   r   r   
get_tokens0  s    zFPSConnection.get_tokensc                 K   s   |  |||S )z/
        Returns the usage of a token.
        rV   rX   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.
        rV   rX   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.
        rV   rX   r   r   r   fund_prepaidH  s    	zFPSConnection.fund_prepaidc                 K   s   |  |||S )zS
        Returns the balance corresponding to the given credit instrument.
        rV   rX   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.
        rV   rX   r   r   r   write_off_debt[  s    
zFPSConnection.write_off_debtZSubscriptionIdc                 K   s   |  |||S )zF
        Returns the transactions for a given subscriptionID.
        rV   rX   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.
        rV   rX   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.r   r=   )ru   rW   )r   r   r   r   r9   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.
        rV   rX   r   r   r   get_payment_instruction  s    z%FPSConnection.get_payment_instruction)*rH   
__module____qualname__Z
APIVersionr   ResponseErrorr   rR   rU   r@   r(   r<   rO   rY   rZ   r[   r\   r^   r_   r`   ra   rb   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   rS   r   r   g   s    




 

 
)rh   r?   Zboto.connectionr   Zboto.fps.exceptionr   Zboto.fps.responser   rK   __all__r	   r   r(   r<   r@   rO   r   r   r   r   r   <module>   s   
