コード例 #1
0
    def create(cls, card_number, cvv, expiry_month, expiry_year, **other_args):
        """
        Creates a payment method.

        Transparent redirects are favored method for creating payment methods.
        Using this call places the burden of PCI compliance on the client since the
        data passes through it.
        ::
            pm = PaymentMethod.create('4242424242424242', '133', '07', '12')
            assert pm.is_sensitive_data_valid
        """
        payload = {
            'payment_method': {
                'card_number': card_number,
                'cvv': cvv,
                'expiry_month': expiry_month,
                'expiry_year': expiry_year,
            }
        }
        optional_data = dict(
            (k, v) for k, v in other_args.iteritems() if k in cls.create_data)
        payload['payment_method'].update(**optional_data)
        payload = dict_to_xml(payload)

        # Send payload and return payment method.
        req = Request(cls.create_url, payload, method='post')
        req.add_header("Content-Type", "application/xml")
        return cls(fetch_url(req))
コード例 #2
0
    def update(self, **other_args):
        """
        Updates a payment method.

        Payment method can't be updated once it has been retained or redacted.
        ::
            pm = PaymentMethod.create('4242424242424242', '133', '07', '12')
            assert pm.is_sensitive_data_valid
            pm.update(first_name='dummy')
            if not pm.errors:
                assert pm.first_name == 'dummy'
            else:
                # deal with pm.errors
        """
        payload = {'payment_method': {}}
        optional_data = dict(
            (k, v) for k, v in other_args.iteritems() if k in self.create_data)
        payload['payment_method'].update(**optional_data)
        payload = dict_to_xml(payload)

        # Send payload and return payment method.
        req = Request(self.update_url % self.payment_method_token,
                      payload,
                      method='put')
        req.add_header("Content-Type", "application/xml")
        res = fetch_url(req)
        self._update_fields(res)
        return self
コード例 #3
0
    def create(cls, card_number, cvv, expiry_month, expiry_year, **other_args):
        """
        Creates a payment method.

        Transparent redirects are favored method for creating payment methods.
        Using this call places the burden of PCI compliance on the client since the
        data passes through it.
        ::
            pm = PaymentMethod.create('4242424242424242', '133', '07', '12')
            assert pm.is_sensitive_data_valid
        """
        payload = {
            'payment_method': {
                'card_number': card_number,
                'cvv': cvv,
                'expiry_month': expiry_month,
                'expiry_year': expiry_year,
            }
        }
        optional_data = dict((k, v) for k, v in other_args.iteritems()
                             if k in cls.create_data)
        payload['payment_method'].update(**optional_data)
        payload = dict_to_xml(payload)

        # Send payload and return payment method.
        req = Request(cls.create_url, payload, method='post')
        req.add_header("Content-Type", "application/xml")
        return cls(fetch_url(req))
コード例 #4
0
    def update(self, **other_args):
        """
        Updates a payment method.

        Payment method can't be updated once it has been retained or redacted.
        ::
            pm = PaymentMethod.create('4242424242424242', '133', '07', '12')
            assert pm.is_sensitive_data_valid
            pm.update(first_name='dummy')
            if not pm.errors:
                assert pm.first_name == 'dummy'
            else:
                # deal with pm.errors
        """
        payload = {
            'payment_method': {
            }
        }
        optional_data = dict((k, v) for k, v in other_args.iteritems()
                             if k in self.create_data)
        payload['payment_method'].update(**optional_data)
        payload = dict_to_xml(payload)

        # Send payload and return payment method.
        req = Request(self.update_url % self.payment_method_token, payload, method='put')
        req.add_header("Content-Type", "application/xml")
        res = fetch_url(req)
        self._update_fields(res)
        return self
コード例 #5
0
 def find(cls, reference_id):
     """
     Gets the transaction details.
     Returns xml data returned from the endpoint converted to python dictionary.
     ::
         trans = Transaction.find(reference_id)
         if not trans.errors:
             # Operate on transaction object
         else:
             # Work on list of errors in trans.errors
     """
     req = Request(cls.find_url % reference_id)
     return cls(fetch_url(req))
コード例 #6
0
 def find(cls, payment_method_token):
     """
     Gets the payment method details.
     Returns xml data returned from the endpoint converted to python dictionary.
     ::
         pm = PaymentMethod.find(token)
         if not pm.errors:
             # Work on pm object here
         else:
             # pm.errors will be a list of errors
     """
     req = Request(cls.find_url % payment_method_token)
     return cls(fetch_url(req))
コード例 #7
0
 def find(cls, payment_method_token):
     """
     Gets the payment method details.
     Returns xml data returned from the endpoint converted to python dictionary.
     ::
         pm = PaymentMethod.find(token)
         if not pm.errors:
             # Work on pm object here
         else:
             # pm.errors will be a list of errors
     """
     req = Request(cls.find_url % payment_method_token)
     return cls(fetch_url(req))
コード例 #8
0
 def find(cls, reference_id):
     """
     Gets the transaction details.
     Returns xml data returned from the endpoint converted to python dictionary.
     ::
         trans = Transaction.find(reference_id)
         if not trans.errors:
             # Operate on transaction object
         else:
             # Work on list of errors in trans.errors
     """
     req = Request(cls.find_url % reference_id)
     return cls(fetch_url(req))
コード例 #9
0
    def _transact(self, endpoint, amount=None):
        """
        Meant to be used internally and shouldn't be called from outside.

        Makes the specified call and returns resultant `transaction`.
        """
        if not getattr(self, 'transaction_token', None):
            raise UnauthorizedTransactionError('Transaction token is missing. Only authorized'
                                               'transactions can make this call.')
        data = dict_to_xml({'transaction':{'amount': amount}})
        req = Request(endpoint % self.transaction_token, data, method='post')
        res = fetch_url(req)
        return type(self)(res)
コード例 #10
0
ファイル: transaction.py プロジェクト: mkmik/www.gittip.com
    def _transact(self, endpoint, amount=None):
        """
        Meant to be used internally and shouldn't be called from outside.

        Makes the specified call and returns resultant `transaction`.
        """
        if not getattr(self, 'transaction_token', None):
            raise UnauthorizedTransactionError(
                'Transaction token is missing. Only authorized'
                'transactions can make this call.')
        data = dict_to_xml({'transaction': {'amount': amount}})
        req = Request(endpoint % self.transaction_token, data, method='post')
        res = fetch_url(req)
        return type(self)(res)
コード例 #11
0
 def retain(self):
     """
     Issues `retain` call to samurai API.
     ::
         pm = PaymentMethod.find(token)
         if not pm.retain().is_retain:
             # Some thing prevented the retention.
             # Check pm.errors
         else:
             # Successfully redacted.
     """
     req = Request(self.retain_url % self.payment_method_token, method='post')
     res = fetch_url(req)
     self._update_fields(res)
     return self
コード例 #12
0
 def retain(self):
     """
     Issues `retain` call to samurai API.
     ::
         pm = PaymentMethod.find(token)
         if not pm.retain().is_retain:
             # Some thing prevented the retention.
             # Check pm.errors
         else:
             # Successfully redacted.
     """
     req = Request(self.retain_url % self.payment_method_token,
                   method='post')
     res = fetch_url(req)
     self._update_fields(res)
     return self
コード例 #13
0
    def _transact(cls, payment_method_token, amount, processor_token,
                  transaction_type, endpoint, options):
        """
        Meant to be used internally and shouldn't be called from outside.

        Makes an `authorize` or `purchase` request.

        `authorize` and `purchase` have same flow, except for `transaction_type` and
        `endpoint`.
        """
        purchase_data = cls._construct_options(payment_method_token, transaction_type,
                                              amount, options)
        # Send payload and return transaction.
        req = Request(endpoint % processor_token, purchase_data, method='post')
        req.add_header("Content-Type", "application/xml")
        return Transaction(fetch_url(req))
コード例 #14
0
    def _transact(cls, payment_method_token, amount, processor_token,
                  transaction_type, endpoint, options):
        """
        Meant to be used internally and shouldn't be called from outside.

        Makes an `authorize` or `purchase` request.

        `authorize` and `purchase` have same flow, except for `transaction_type` and
        `endpoint`.
        """
        purchase_data = cls._construct_options(payment_method_token,
                                               transaction_type, amount,
                                               options)
        # Send payload and return transaction.
        req = Request(endpoint % processor_token, purchase_data, method='post')
        req.add_header("Content-Type", "application/xml")
        return Transaction(fetch_url(req))