Ejemplo n.º 1
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     if "accepted_at" in attributes:
         self.accepted_at = datetime.strptime(attributes["accepted_at"],
                                              "%Y-%m-%dT%H:%M:%S.%fZ")
     else:
         self.accepted_at = None
Ejemplo n.º 2
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     if attributes.get('iban_bank_account') is not None:
         self.iban_bank_account = IbanBankAccount(gateway,
                                                  self.iban_bank_account)
     else:
         self.iban_bank_account = None
Ejemplo n.º 3
0
 def __init__(self, attributes):
     Resource.__init__(self, attributes)
     self.price = Decimal(self.price)
     if "transactions" in attributes:
         self.transactions = [
             Transaction(transaction) for transaction in self.transactions
         ]
Ejemplo n.º 4
0
    def create(params):
        """
        Creates a transaction. Amount and type are required. Also, a credit card,
        customer_id or payment_method_token is required. ::

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "payment_method_token": "my_token"
            })

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "credit_card": {
                    "number": "4111111111111111",
                    "expiration_date": "12/2012"
                }
            })

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "customer_id": "my_customer_id"
            })
        """

        Resource.verify_keys(params, Transaction.create_signature())
        return Transaction._post("/transactions", {"transaction": params})
Ejemplo n.º 5
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "three_d_secure_info" in attributes and not attributes["three_d_secure_info"] is None:
            self.three_d_secure_info = ThreeDSecureInfo(attributes["three_d_secure_info"])
        else:
            self.three_d_secure_info = None
Ejemplo n.º 6
0
    def test_verify_keys_allows_raw_data(self):
        raw_string = str.encode("raw_string")
        assert isinstance(raw_string, TestHelper.raw_type)

        signature = [{"customer": [{"custom_fields": [raw_string]}]}]
        params = {"customer": {"custom_fields": {raw_string: raw_string}}}
        Resource.verify_keys(params, signature)
Ejemplo n.º 7
0
    def test_verify_keys_allows_text(self):
        text_string = u"text_string"
        assert isinstance(text_string, TestHelper.text_type)

        signature = [{"customer": [{"custom_fields": [text_string]}]}]
        params = {"customer": {"custom_fields": {text_string: text_string}}}
        Resource.verify_keys(params, signature)
Ejemplo n.º 8
0
    def create(params={}):
        """
        Create an Address. A customer_id is required::

            customer = braintree.Customer.create().customer
            result = braintree.Address.create({
                "customer_id": customer.id,
                "first_name": "John",
                ...
            })
        """

        Resource.verify_keys(params, Address.create_signature())
        if not "customer_id" in params:
            raise KeyError("customer_id must be provided")
        if not re.search("\A[0-9A-Za-z_-]+\Z", params["customer_id"]):
            raise KeyError("customer_id contains invalid characters")

        response = Http().post(
            "/customers/" + params.pop("customer_id") + "/addresses",
            {"address": params})
        if "address" in response:
            return SuccessfulResult({"address": Address(response["address"])})
        elif "api_error_response" in response:
            return ErrorResult(response["api_error_response"])
Ejemplo n.º 9
0
 def create(self, params=None):
     if params is None:
         params = {}
     Resource.verify_keys(params,
                          MerchantAccountGateway._create_signature())
     return self._post("/merchant_accounts/create_via_api",
                       {"merchant_account": params})
 def update(self, paypal_account_token, params={}):
     Resource.verify_keys(params, PayPalAccount.signature())
     response = self.config.http().put("/payment_methods/paypal_account/" + paypal_account_token, {"paypal_account": params})
     if "paypal_account" in response:
         return SuccessfulResult({"paypal_account": PayPalAccount(self.gateway, response["paypal_account"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
 def create(self,
            payment_method_token,
            params={"payment_method_nonce": {}}):
     try:
         schema = [{
             "payment_method_nonce": [
                 "merchant_account_id", "authentication_insight", {
                     "authentication_insight_options": [
                         "amount", "recurring_customer_consent",
                         "recurring_max_amount"
                     ]
                 }
             ]
         }]
         Resource.verify_keys(params, schema)
         response = self.config.http().post(
             self.config.base_merchant_path() + "/payment_methods/" +
             payment_method_token + "/nonces", params)
         if "api_error_response" in response:
             return ErrorResult(self.gateway,
                                response["api_error_response"])
         else:
             payment_method_nonce = self._parse_payment_method_nonce(
                 response)
             return SuccessfulResult(
                 {"payment_method_nonce": payment_method_nonce})
     except NotFoundError:
         raise NotFoundError("payment method with token " +
                             repr(payment_method_token) + " not found")
Ejemplo n.º 12
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "api_error_response" in attributes["subject"]:
            node_wrapper = attributes["subject"]["api_error_response"]
        else:
            node_wrapper = attributes["subject"]

        if "subscription" in node_wrapper:
            self.subscription = Subscription(gateway,
                                             node_wrapper['subscription'])
        elif "merchant_account" in node_wrapper:
            self.merchant_account = MerchantAccount(
                gateway, node_wrapper['merchant_account'])
        elif "transaction" in node_wrapper:
            self.transaction = Transaction(gateway,
                                           node_wrapper['transaction'])
        elif "partner_merchant" in node_wrapper:
            self.partner_merchant = PartnerMerchant(
                gateway, node_wrapper['partner_merchant'])
        elif "disbursement" in node_wrapper:
            self.disbursement = Disbursement(gateway,
                                             node_wrapper['disbursement'])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
Ejemplo n.º 13
0
 def __init__(self, gateway, attributes):
     if "next_bill_amount" in attributes.keys():
         self._next_bill_amount = Decimal(attributes["next_bill_amount"])
         del (attributes["next_bill_amount"])
     Resource.__init__(self, gateway, attributes)
     if "price" in attributes:
         self.price = Decimal(self.price)
     if "balance" in attributes:
         self.balance = Decimal(self.balance)
     if "next_billing_period_amount" in attributes:
         self.next_billing_period_amount = Decimal(
             self.next_billing_period_amount)
     if "add_ons" in attributes:
         self.add_ons = [AddOn(gateway, add_on) for add_on in self.add_ons]
     if "descriptor" in attributes:
         self.descriptor = Descriptor(gateway, attributes.pop("descriptor"))
     if "discounts" in attributes:
         self.discounts = [
             Discount(gateway, discount) for discount in self.discounts
         ]
     if "transactions" in attributes:
         self.transactions = [
             Transaction(gateway, transaction)
             for transaction in self.transactions
         ]
Ejemplo n.º 14
0
    def generate(self, params=None):
        if params is None:
            params = {}
        if "options" in params and "customer_id" not in params:
            for option in [
                    "verify_card", "make_default",
                    "fail_on_duplicate_payment_method"
            ]:
                if option in params["options"]:
                    raise exceptions.InvalidSignatureError(
                        "cannot specify %s without a customer_id" % option)

        if "version" not in params:
            params["version"] = 2

        Resource.verify_keys(params, ClientToken.generate_signature())
        params = {'client_token': params}

        response = self.config.http().post(
            self.config.base_merchant_path() + "/client_token", params)

        if "client_token" in response:
            return response["client_token"]["value"]
        else:
            raise ValueError(response["api_error_response"]["message"])
Ejemplo n.º 15
0
    def __init__(self, gateway, attributes):
        if "refund_id" in attributes.keys():
            self._refund_id = attributes["refund_id"]
            del(attributes["refund_id"])
        else:
            self._refund_id = None

        Resource.__init__(self, gateway, attributes)

        self.amount = Decimal(self.amount)
        if self.tax_amount:
            self.tax_amount = Decimal(self.tax_amount)
        if "billing" in attributes:
            self.billing_details = Address(gateway, attributes.pop("billing"))
        if "credit_card" in attributes:
            self.credit_card_details = CreditCard(gateway, attributes.pop("credit_card"))
        if "customer" in attributes:
            self.customer_details = Customer(gateway, attributes.pop("customer"))
        if "shipping" in attributes:
            self.shipping_details = Address(gateway, attributes.pop("shipping"))
        if "add_ons" in attributes:
            self.add_ons = [AddOn(gateway, add_on) for add_on in self.add_ons]
        if "discounts" in attributes:
            self.discounts = [Discount(gateway, discount) for discount in self.discounts]
        if "status_history" in attributes:
            self.status_history = [StatusEvent(gateway, status_event) for status_event in self.status_history]
        if "descriptor" in attributes:
            self.descriptor = Descriptor(gateway, attributes.pop("descriptor"))
    def create(params):
        """
        Creates a transaction. Amount and type are required. Also, a credit card,
        customer_id or payment_method_token is required. ::

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "payment_method_token": "my_token"
            })

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "credit_card": {
                    "number": "4111111111111111",
                    "expiration_date": "12/2012"
                }
            })

            result = braintree.Transaction.sale({
                "type": braintree.Transaction.Type.Sale,
                "amount": "100.00",
                "customer_id": "my_customer_id"
            })
        """

        Resource.verify_keys(params, Transaction.create_signature())
        return Transaction._post("/transactions", {"transaction": params})
Ejemplo n.º 17
0
    def __init__(self, gateway, attributes):
        if "refund_id" in attributes.keys():
            self._refund_id = attributes["refund_id"]
            del(attributes["refund_id"])
        else:
            self._refund_id = None

        Resource.__init__(self, gateway, attributes)

        self.amount = Decimal(self.amount)
        if self.tax_amount:
            self.tax_amount = Decimal(self.tax_amount)
        if "billing" in attributes:
            self.billing_details = Address(gateway, attributes.pop("billing"))
        if "credit_card" in attributes:
            self.credit_card_details = CreditCard(gateway, attributes.pop("credit_card"))
        if "customer" in attributes:
            self.customer_details = Customer(gateway, attributes.pop("customer"))
        if "shipping" in attributes:
            self.shipping_details = Address(gateway, attributes.pop("shipping"))
        if "add_ons" in attributes:
            self.add_ons = [AddOn(gateway, add_on) for add_on in self.add_ons]
        if "discounts" in attributes:
            self.discounts = [Discount(gateway, discount) for discount in self.discounts]
        if "status_history" in attributes:
            self.status_history = [StatusEvent(gateway, status_event) for status_event in self.status_history]
        if "subscription" in attributes:
            self.subscription_details = SubscriptionDetails(attributes.pop("subscription"))
        if "descriptor" in attributes:
            self.descriptor = Descriptor(gateway, attributes.pop("descriptor"))
Ejemplo n.º 18
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     if "subscriptions" in attributes:
         self.subscriptions = [
             braintree.subscription.Subscription(gateway, subscription)
             for subscription in self.subscriptions
         ]
Ejemplo n.º 19
0
 def create(self, params={}):
     Resource.verify_keys(params, Subscription.create_signature())
     response = self.config.http().post(self.config.base_merchant_path() + "/subscriptions", {"subscription": params})
     if "subscription" in response:
         return SuccessfulResult({"subscription": Subscription(self.gateway, response["subscription"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 20
0
 def __init__(self, attributes):
     Resource.__init__(self, attributes)
     self.is_expired = self.expired
     if "billing_address" in attributes:
         self.billing_address = Address(self.billing_address)
     if "subscriptions" in attributes:
         self.subscriptions = [braintree.subscription.Subscription(subscription) for subscription in self.subscriptions]
Ejemplo n.º 21
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)
        if hasattr(self, 'expired'):
            self.is_expired = self.expired

        if "subscriptions" in attributes:
            self.subscriptions = [braintree.subscription.Subscription(gateway, subscription) for subscription in self.subscriptions]
Ejemplo n.º 22
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     self.individual_details = IndividualDetails(attributes.get("individual", {}))
     self.business_details = BusinessDetails(attributes.get("business", {}))
     self.funding_details = FundingDetails(attributes.get("funding", {}))
     if "master_merchant_account" in attributes:
         self.master_merchant_account = MerchantAccount(gateway, attributes.pop("master_merchant_account"))
 def update(self, subscription_id, params={}):
     Resource.verify_keys(params, Subscription.update_signature())
     response = self.config.http().put("/subscriptions/" + subscription_id, {"subscription": params})
     if "subscription" in response:
         return SuccessfulResult({"subscription": Subscription(self.gateway, response["subscription"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 24
0
 def tr_data_for_create(self, tr_data, redirect_url):
     Resource.verify_keys(tr_data,
                          [{
                              "credit_card": CreditCard.create_signature()
                          }])
     tr_data["kind"] = TransparentRedirect.Kind.CreatePaymentMethod
     return self.gateway.transparent_redirect.tr_data(tr_data, redirect_url)
 def update(self, credit_card_token, params={}):
     Resource.verify_keys(params, CreditCard.update_signature())
     response = self.config.http().put("/payment_methods/" + credit_card_token, {"credit_card": params})
     if "credit_card" in response:
         return SuccessfulResult({"credit_card": CreditCard(self.gateway, response["credit_card"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
 def update(self, paypal_account_token, params={}):
     Resource.verify_keys(params, PayPalAccount.signature())
     response = self.config.http().put("/payment_methods/paypal_account/" + paypal_account_token, {"paypal_account": params})
     if "paypal_account" in response:
         return SuccessfulResult({"paypal_account": PayPalAccount(self.gateway, response["paypal_account"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 27
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)
        self.payment_methods = []

        if "credit_cards" in attributes:
            self.credit_cards = [CreditCard(gateway, credit_card) for credit_card in self.credit_cards]
            self.payment_methods += self.credit_cards
        if "addresses" in attributes:
            self.addresses = [Address(gateway, address) for address in self.addresses]

        if "paypal_accounts" in attributes:
            self.paypal_accounts  = [PayPalAccount(gateway, paypal_account) for paypal_account in self.paypal_accounts]
            self.payment_methods += self.paypal_accounts

        if "apple_pay_cards" in attributes:
            self.apple_pay_cards  = [ApplePayCard(gateway, apple_pay_card) for apple_pay_card in self.apple_pay_cards]
            self.payment_methods += self.apple_pay_cards

        if "android_pay_cards" in attributes:
            self.android_pay_cards  = [AndroidPayCard(gateway, android_pay_card) for android_pay_card in self.android_pay_cards]
            self.payment_methods += self.android_pay_cards

        if "europe_bank_accounts" in attributes:
            self.europe_bank_accounts = [EuropeBankAccount(gateway, europe_bank_account) for europe_bank_account in self.europe_bank_accounts]
            self.payment_methods += self.europe_bank_accounts

        if "coinbase_accounts" in attributes:
            self.coinbase_accounts = [CoinbaseAccount(gateway, coinbase_account) for coinbase_account in self.coinbase_accounts]
            self.payment_methods += self.coinbase_accounts
 def create(self, params={}):
     Resource.verify_keys(params, Subscription.create_signature())
     response = self.config.http().post(self.config.base_merchant_path() + "/subscriptions", {"subscription": params})
     if "subscription" in response:
         return SuccessfulResult({"subscription": Subscription(self.gateway, response["subscription"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 29
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "api_error_response" in attributes["subject"]:
            node_wrapper = attributes["subject"]["api_error_response"]
        else:
            node_wrapper = attributes["subject"]

        if "subscription" in node_wrapper:
            self.subscription = Subscription(gateway, node_wrapper['subscription'])
        elif "merchant_account" in node_wrapper:
            self.merchant_account = MerchantAccount(gateway, node_wrapper['merchant_account'])
        elif "transaction" in node_wrapper:
            self.transaction = Transaction(gateway, node_wrapper['transaction'])
        elif "partner_merchant" in node_wrapper:
            self.partner_merchant = PartnerMerchant(gateway, node_wrapper['partner_merchant'])
        elif "disbursement" in node_wrapper:
            self.disbursement = Disbursement(gateway, node_wrapper['disbursement'])
        elif "dispute" in node_wrapper:
            self.dispute = Dispute(node_wrapper['dispute'])
        elif "account_updater_daily_report" in node_wrapper:
            self.account_updater_daily_report = AccountUpdaterDailyReport(gateway, node_wrapper['account_updater_daily_report'])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
Ejemplo n.º 30
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     if "price" in attributes:
         self.price = Decimal(self.price)
     if "balance" in attributes:
         self.balance = Decimal(self.balance)
     if "next_billing_period_amount" in attributes:
         self.next_billing_period_amount = Decimal(
             self.next_billing_period_amount)
     if "add_ons" in attributes:
         self.add_ons = [AddOn(gateway, add_on) for add_on in self.add_ons]
     if "descriptor" in attributes:
         self.descriptor = Descriptor(gateway, attributes.pop("descriptor"))
     if "description" in attributes:
         self.description = attributes["description"]
     if "discounts" in attributes:
         self.discounts = [
             Discount(gateway, discount) for discount in self.discounts
         ]
     if "status_history" in attributes:
         self.status_history = [
             SubscriptionStatusEvent(gateway, status_event)
             for status_event in self.status_history
         ]
     if "transactions" in attributes:
         self.transactions = [
             Transaction(gateway, transaction)
             for transaction in self.transactions
         ]
Ejemplo n.º 31
0
 def __init__(self, gateway, attributes):
     Resource.__init__(self, gateway, attributes)
     self.individual_details = IndividualDetails(attributes.get("individual", {}))
     self.business_details = BusinessDetails(attributes.get("business", {}))
     self.funding_details = FundingDetails(attributes.get("funding", {}))
     if "master_merchant_account" in attributes:
         self.master_merchant_account = MerchantAccount(gateway, attributes.pop("master_merchant_account"))
Ejemplo n.º 32
0
 def update(self, customer_id, params={}):
     Resource.verify_keys(params, Customer.update_signature())
     response = self.config.http().put(self.config.base_merchant_path() + "/customers/" + customer_id, {"customer": params})
     if "customer" in response:
         return SuccessfulResult({"customer": Customer(self.gateway, response["customer"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
 def tr_data_for_sale(self, tr_data, redirect_url):
     if "transaction" not in tr_data:
         tr_data["transaction"] = {}
     tr_data["transaction"]["type"] = Transaction.Type.Sale
     Resource.verify_keys(tr_data, [{"transaction": Transaction.create_signature()}])
     tr_data["kind"] = TransparentRedirect.Kind.CreateTransaction
     return self.gateway.transparent_redirect.tr_data(tr_data, redirect_url)
 def tr_data_for_credit(self, tr_data, redirect_url):
     if "transaction" not in tr_data:
         tr_data["transaction"] = {}
     tr_data["transaction"]["type"] = Transaction.Type.Credit
     Resource.verify_keys(tr_data, [{"transaction": Transaction.create_signature()}])
     tr_data["kind"] = TransparentRedirect.Kind.CreateTransaction
     return self.gateway.transparent_redirect.tr_data(tr_data, redirect_url)
 def update(self, subscription_id, params={}):
     Resource.verify_keys(params, Subscription.update_signature())
     response = self.config.http().put("/subscriptions/" + subscription_id, {"subscription": params})
     if "subscription" in response:
         return SuccessfulResult({"subscription": Subscription(self.gateway, response["subscription"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "three_d_secure_info" in attributes and not attributes["three_d_secure_info"] == None:
            self.three_d_secure_info = ThreeDSecureInfo(attributes["three_d_secure_info"])
        else:
            self.three_d_secure_info = None
Ejemplo n.º 37
0
 def tr_data_for_update(tr_data, redirect_url):
     """
     Builds tr_data for CreditCard updating.
     """
     Resource.verify_keys(tr_data, ["payment_method_token", {"credit_card": CreditCard.update_signature()}])
     tr_data["kind"] = TransparentRedirect.Kind.UpdatePaymentMethod
     return TransparentRedirect.tr_data(tr_data, redirect_url)
Ejemplo n.º 38
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "source_merchant_id" not in attributes:
            self.source_merchant_id = None

        if "api_error_response" in attributes["subject"]:
            node_wrapper = attributes["subject"]["api_error_response"]
        else:
            node_wrapper = attributes["subject"]

        if "subscription" in node_wrapper:
            self.subscription = Subscription(gateway,
                                             node_wrapper['subscription'])
        elif "merchant_account" in node_wrapper:
            self.merchant_account = MerchantAccount(
                gateway, node_wrapper['merchant_account'])
        elif "transaction" in node_wrapper:
            self.transaction = Transaction(gateway,
                                           node_wrapper['transaction'])
        elif "connected_merchant_status_transitioned" in node_wrapper:
            self.connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned(
                gateway,
                node_wrapper['connected_merchant_status_transitioned'])
        elif "connected_merchant_paypal_status_changed" in node_wrapper:
            self.connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged(
                gateway,
                node_wrapper['connected_merchant_paypal_status_changed'])
        elif "partner_merchant" in node_wrapper:
            self.partner_merchant = PartnerMerchant(
                gateway, node_wrapper['partner_merchant'])
        elif "oauth_application_revocation" in node_wrapper:
            self.oauth_access_revocation = OAuthAccessRevocation(
                node_wrapper["oauth_application_revocation"])
        elif "disbursement" in node_wrapper:
            self.disbursement = Disbursement(gateway,
                                             node_wrapper['disbursement'])
        elif "dispute" in node_wrapper:
            self.dispute = Dispute(node_wrapper['dispute'])
        elif "account_updater_daily_report" in node_wrapper:
            self.account_updater_daily_report = AccountUpdaterDailyReport(
                gateway, node_wrapper['account_updater_daily_report'])
        elif "ideal_payment" in node_wrapper:
            self.ideal_payment = IdealPayment(gateway,
                                              node_wrapper['ideal_payment'])
        elif "granted_payment_instrument_update" in node_wrapper:
            self.granted_payment_instrument_update = GrantedPaymentInstrumentUpdate(
                gateway, node_wrapper["granted_payment_instrument_update"])
        elif WebhookNotification.Kind.GrantedPaymentMethodRevoked == attributes[
                "kind"]:
            self.revoked_payment_method_metadata = RevokedPaymentMethodMetadata(
                gateway, node_wrapper)
        elif "local_payment" in node_wrapper:
            self.local_payment_completed = LocalPaymentCompleted(
                gateway, node_wrapper["local_payment"])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
Ejemplo n.º 39
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "merchant_accounts" in attributes:
            self.merchant_accounts = [
                MerchantAccount(gateway, ma)
                for ma in attributes.get("merchant_accounts")
            ]
Ejemplo n.º 40
0
 def update(self, merchant_account_id, params=None):
     if params is None:
         params = {}
     Resource.verify_keys(params,
                          MerchantAccountGateway._update_signature())
     return self._put(
         "/merchant_accounts/%s/update_via_api" % merchant_account_id,
         {"merchant_account": params})
Ejemplo n.º 41
0
 def update_details(self, transaction_id, params={}):
     Resource.verify_keys(params, Transaction.update_details_signature())
     response = self.config.http().put(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/update_details",
             {"transaction": params})
     if "transaction" in response:
         return SuccessfulResult({"transaction": Transaction(self.gateway, response["transaction"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 42
0
 def tr_data_for_update(self, tr_data, redirect_url):
     Resource.verify_keys(
         tr_data,
         ["customer_id", {
             "customer": Customer.update_signature()
         }])
     tr_data["kind"] = TransparentRedirect.Kind.UpdateCustomer
     return self.gateway.transparent_redirect.tr_data(tr_data, redirect_url)
Ejemplo n.º 43
0
 def test_verify_keys_escapes_brackets_in_signature(self):
     signature = [
         {"customer": [{"custom_fields": ["__any_key__"]}]}
     ]
     params = {
         "customer_id": "value",
     }
     Resource.verify_keys(params, signature)
Ejemplo n.º 44
0
    def tr_data_for_create(tr_data, redirect_url):
        """
        Builds tr_data for CreditCard creation.
        """

        Resource.verify_keys(tr_data, [{"credit_card": CreditCard.create_signature()}])
        tr_data["kind"] = TransparentRedirect.Kind.CreatePaymentMethod
        return TransparentRedirect.tr_data(tr_data, redirect_url)
Ejemplo n.º 45
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)
        if "credit_cards" in attributes:
            self.credit_cards = [CreditCard(gateway, credit_card) for credit_card in self.credit_cards]
        if "addresses" in attributes:
            self.addresses = [Address(gateway, address) for address in self.addresses]

        if "paypal_accounts" in attributes:
            self.paypal_accounts  = [PayPalAccount(gateway, paypal_account) for paypal_account in self.paypal_accounts]
Ejemplo n.º 46
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

        if "billing_address" in attributes:
            self.billing_address = Address(gateway, self.billing_address)
        else:
            self.billing_address = None

        if "subscriptions" in attributes:
            self.subscriptions = [braintree.subscription.Subscription(gateway, subscription) for subscription in self.subscriptions]
Ejemplo n.º 47
0
 def test_verify_keys_works_with_array_param(self):
     signature = [
         {"customer": ["one", "two"]}
     ]
     params = {
         "customer": {
             "one": "foo"
         }
     }
     Resource.verify_keys(params, signature)
    def delete(self, payment_method_token, options={}):
        Resource.verify_keys(options, PaymentMethod.delete_signature())
        query_param = ""
        if options:
            if 'revoke_all_grants' in options:
                options['revoke_all_grants'] = str(options['revoke_all_grants']).lower()
            query_param = "?" + urlencode(options)

        self.config.http().delete(self.config.base_merchant_path() + "/payment_methods/any/" + payment_method_token + query_param)
        return SuccessfulResult()
Ejemplo n.º 49
0
 def test_verify_keys_raises_on_bad_array_param(self):
     signature = [
         {"customer": ["one", "two"]}
     ]
     params = {
         "customer": {
             "invalid": "foo"
         }
     }
     Resource.verify_keys(params, signature)
Ejemplo n.º 50
0
 def update(self, customer_id, address_id, params={}):
     Resource.verify_keys(params, Address.update_signature())
     response = self.config.http().put(
         "/customers/" + customer_id + "/addresses/" + address_id,
         {"address": params}
     )
     if "address" in response:
         return SuccessfulResult({"address": Address(self.gateway, response["address"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
 def submit_for_settlement(self, transaction_id, amount=None, params={}):
     Resource.verify_keys(params, Transaction.submit_for_settlement_signature())
     transaction_params = {"amount": amount}
     transaction_params.update(params)
     response = self.config.http().put(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/submit_for_settlement",
             {"transaction": transaction_params})
     if "transaction" in response:
         return SuccessfulResult({"transaction": Transaction(self.gateway, response["transaction"])})
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
Ejemplo n.º 52
0
    def __init__(self, gateway, attributes):
        if "refund_id" in attributes:
            self._refund_id = attributes["refund_id"]
            del(attributes["refund_id"])
        else:
            self._refund_id = None

        Resource.__init__(self, gateway, attributes)

        self.amount = Decimal(self.amount)
        if self.tax_amount:
            self.tax_amount = Decimal(self.tax_amount)
        if "billing" in attributes:
            self.billing_details = Address(gateway, attributes.pop("billing"))
        if "credit_card" in attributes:
            self.credit_card_details = CreditCard(gateway, attributes.pop("credit_card"))
        if "paypal" in attributes:
            self.paypal_details = PayPalAccount(gateway, attributes.pop("paypal"))
        if "europe_bank_account" in attributes:
            self.europe_bank_account_details = EuropeBankAccount(gateway, attributes.pop("europe_bank_account"))
        if "apple_pay" in attributes:
            self.apple_pay_details = ApplePayCard(gateway, attributes.pop("apple_pay"))
        if "coinbase_account" in attributes:
            self.coinbase_details = CoinbaseAccount(gateway, attributes.pop("coinbase_account"))
        if "android_pay_card" in attributes:
            self.android_pay_card_details = AndroidPayCard(gateway, attributes.pop("android_pay_card"))
        if "customer" in attributes:
            self.customer_details = Customer(gateway, attributes.pop("customer"))
        if "shipping" in attributes:
            self.shipping_details = Address(gateway, attributes.pop("shipping"))
        if "add_ons" in attributes:
            self.add_ons = [AddOn(gateway, add_on) for add_on in self.add_ons]
        if "discounts" in attributes:
            self.discounts = [Discount(gateway, discount) for discount in self.discounts]
        if "status_history" in attributes:
            self.status_history = [StatusEvent(gateway, status_event) for status_event in self.status_history]
        if "subscription" in attributes:
            self.subscription_details = SubscriptionDetails(attributes.pop("subscription"))
        if "descriptor" in attributes:
            self.descriptor = Descriptor(gateway, attributes.pop("descriptor"))
        if "disbursement_details" in attributes:
            self.disbursement_details = DisbursementDetail(attributes.pop("disbursement_details"))
        if "disputes" in attributes:
            self.disputes = [Dispute(dispute) for dispute in self.disputes]
        if "payment_instrument_type" in attributes:
            self.payment_instrument_type = attributes["payment_instrument_type"]

        if "risk_data" in attributes:
            self.risk_data = RiskData(attributes["risk_data"])
        else:
            self.risk_data = None
        if "three_d_secure_info" in attributes and not attributes["three_d_secure_info"] == None:
            self.three_d_secure_info = ThreeDSecureInfo(attributes["three_d_secure_info"])
        else:
            self.three_d_secure_info = None
    def tr_data_for_sale(tr_data, redirect_url):
        """
        Builds tr_data for a Transaction of type Sale
        """

        if "transaction" not in tr_data:
            tr_data["transaction"] = {}
        tr_data["transaction"]["type"] = Transaction.Type.Sale
        Resource.verify_keys(tr_data, [{"transaction": Transaction.create_signature()}])
        tr_data["kind"] = TransparentRedirect.Kind.CreateTransaction
        return TransparentRedirect.tr_data(tr_data, redirect_url)
    def generate(self, params):
        if params:
            Resource.verify_keys(params, ClientToken.generate_signature())
            params = {'client_token': params}

        response = self.config.http().post("/client_token", params)

        if "client_token" in response:
            return response["client_token"]["value"]
        else:
            raise exceptions.ValueError(response["api_error_response"]["message"])
Ejemplo n.º 55
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)
        if attributes.get("ach_mandate") is not None:
            self.ach_mandate = AchMandate(gateway, self.ach_mandate)
        else:
            self.ach_mandate = None

        if attributes.get("verifications") is not None:
            self.verifications = [UsBankAccountVerification(gateway, v) for v in self.verifications]
        else:
            self.verifications = None
    def update(self, payment_method_token, params):
        Resource.verify_keys(params, PaymentMethod.update_signature())
        try:
            if payment_method_token is None or payment_method_token.strip() == "":
                raise NotFoundError()

            return self._put(
                "/payment_methods/any/" + payment_method_token,
                {"payment_method": params}
            )
        except NotFoundError:
            raise NotFoundError("payment method with token " + repr(payment_method_token) + " not found")