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)
Esempio n. 2
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"])
 def release_from_escrow(self, transaction_id):
     response = self.config.http().put(
         "/transactions/" + transaction_id + "/release_from_escrow", {})
     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"])
Esempio n. 4
0
 def _post(self, url, params={}):
     response = self.config.http().post(
         self.config.base_merchant_path() + url, 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"])
Esempio n. 5
0
 def find(self, transaction_id):
     try:
         if transaction_id == None or transaction_id.strip() == "":
             raise NotFoundError()
         response = self.config.http().get("/transactions/" +
                                           transaction_id)
         return Transaction(self.gateway, response["transaction"])
     except NotFoundError:
         raise NotFoundError("transaction with id " + transaction_id +
                             " not found")
Esempio n. 6
0
 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)
Esempio n. 7
0
 def void(self, transaction_id):
     response = self.config.http().put("/transactions/" + transaction_id +
                                       "/void")
     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"])
 def retry_charge(self, subscription_id, amount=None):
     response = self.config.http().post("/transactions", {"transaction": {
         "amount": amount,
         "subscription_id": subscription_id,
         "type": Transaction.Type.Sale
         }})
     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"])
 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"])
Esempio n. 10
0
 def find(self, transaction_id):
     try:
         if transaction_id is None or transaction_id.strip() == "":
             raise NotFoundError()
         response = self.config.http().get(
             self.config.base_merchant_path() + "/transactions/" +
             transaction_id)
         return Transaction(self.gateway, response["transaction"])
     except NotFoundError:
         raise NotFoundError("transaction with id " + repr(transaction_id) +
                             " not found")
Esempio n. 11
0
 def retry_charge(self, subscription_id, amount=None, submit_for_settlement=False):
     response = self.config.http().post(self.config.base_merchant_path() + "/transactions", {"transaction": {
         "amount": amount,
         "subscription_id": subscription_id,
         "type": Transaction.Type.Sale,
         "options": {"submit_for_settlement": submit_for_settlement}
         }})
     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"])
Esempio n. 12
0
 def cancel_release(self, transaction_id):
     response = self.config.http().put(
         self.config.base_merchant_path() + "/transactions/" +
         transaction_id + "/cancel_release", {})
     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"])
    def refund(self, transaction_id, amount=None):
        """
        Refunds an existing transaction. It expects a transaction_id. ::

            result = braintree.Transaction.refund("my_transaction_id")
        """

        response = self.config.http().post("/transactions/" + transaction_id + "/refund", {"transaction": {"amount": amount}})
        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"])
Esempio n. 14
0
    def refund(self, transaction_id, amount_or_options=None):
        """
        Refunds an existing transaction. It expects a transaction_id. ::

            result = braintree.Transaction.refund("my_transaction_id")
        """
        if isinstance(amount_or_options, dict):
            options = amount_or_options
        else:
            options = {"amount": amount_or_options}
        Resource.verify_keys(options, Transaction.refund_signature())
        response = self.config.http().post(
            self.config.base_merchant_path() + "/transactions/" +
            transaction_id + "/refund", {"transaction": options})
        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"])
 def submit_for_partial_settlement(self,
                                   transaction_id,
                                   amount,
                                   params=None):
     if params is None:
         params = {}
     Resource.verify_keys(params,
                          Transaction.submit_for_settlement_signature())
     transaction_params = {"amount": amount}
     transaction_params.update(params)
     response = self.config.http().post(
         self.config.base_merchant_path() + "/transactions/" +
         transaction_id + "/submit_for_partial_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"])
    def hold_in_escrow(self, transaction_id):
        """
        Holds an existing submerchant transaction for escrow. It expects a transaction_id. ::

            result = braintree.Transaction.hold_in_escrow("my_transaction_id")
        """

        response = self.config.http().put("/transactions/" + transaction_id + "/hold_in_escrow", {})
        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"])
 def __fetch(self, query, ids):
     criteria = self.__criteria(query)
     criteria[
         "ids"] = braintree.transaction_search.TransactionSearch.ids.in_list(
             ids).to_param()
     response = self.config.http().post("/transactions/advanced_search",
                                        {"search": criteria})
     return [
         Transaction(self.gateway, item)
         for item in ResourceCollection._extract_as_array(
             response["credit_card_transactions"], "transaction")
     ]
Esempio n. 18
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"])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
 def submit_for_settlement(self, transaction_id, amount=None):
     response = self.config.http().put(
         "/transactions/" + transaction_id + "/submit_for_settlement",
         {"transaction": {
             "amount": amount
         }})
     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"])
Esempio n. 20
0
 def retryCharge(subscription_id, amount=None):
     response = Http().post(
         "/transactions", {
             "transaction": {
                 "amount": amount,
                 "subscription_id": subscription_id,
                 "type": Transaction.Type.Sale
             }
         })
     if "transaction" in response:
         return SuccessfulResult(
             {"transaction": Transaction(response["transaction"])})
     elif "api_error_response" in response:
         return ErrorResult(response["api_error_response"])
Esempio n. 21
0
 def submit_for_partial_settlement(self, transaction_id, amount):
     response = self.config.http().post(
         self.config.base_merchant_path() + "/transactions/" +
         transaction_id + "/submit_for_partial_settlement",
         {"transaction": {
             "amount": amount
         }})
     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"])
Esempio n. 22
0
def transaction(**kw):
    transaction = {
        'amount': '5.00',
        'card_type': 'visa',
        'created_at': datetime.now(),
        'id': 'test-id',
        'last_4': '7890',
        'tax_amount': '0.00',
        'token': 'da-token',
        'updated_at': datetime.now(),
        'currency_iso_code': 'USD',
    }
    transaction.update(**kw)
    return Transaction(None, transaction)
Esempio n. 23
0
 def __fetch(self, query, ids):
     criteria = self.__criteria(query)
     criteria[
         "ids"] = braintree.transaction_search.TransactionSearch.ids.in_list(
             ids).to_param()
     response = self.config.http().post(
         self.config.base_merchant_path() + "/transactions/advanced_search",
         {"search": criteria})
     if "credit_card_transactions" in response:
         return [
             Transaction(self.gateway, item)
             for item in ResourceCollection._extract_as_array(
                 response["credit_card_transactions"], "transaction")
         ]
     else:
         raise DownForMaintenanceError("search timeout")
Esempio n. 24
0
    def refund(self, transaction_id, amount_or_options=None):
        """
        Refunds an existing transaction. It expects a transaction_id. ::

            result = braintree.Transaction.refund("my_transaction_id")
        """
        if isinstance(amount_or_options, dict):
            options = amount_or_options
        else:
            options = {
                "amount": amount_or_options
            }
        Resource.verify_keys(options, Transaction.refund_signature())
        response = self.config.http().post(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/refund", {"transaction": options})
        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"])
Esempio n. 25
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]
    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'])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
Esempio n. 27
0
 def create(self, params):
     Resource.verify_keys(params, Transaction.create_signature())
     return self._post("/transactions", {"transaction": params})
Esempio n. 28
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'])
        # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
        # DEPRECATED If you're looking to accept iDEAL as a payment method contact [email protected] for a solution.
        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 attributes["kind"] in [
                WebhookNotification.Kind.GrantedPaymentMethodRevoked,
                WebhookNotification.Kind.PaymentMethodRevokedByCustomer
        ]:
            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']
Esempio n. 29
0
 def clone_transaction(self, transaction_id, params):
     Resource.verify_keys(params, Transaction.clone_signature())
     return self._post("/transactions/" + transaction_id + "/clone",
                       {"transaction-clone": params})
 def create(self, params):
     Resource.verify_keys(params, Transaction.create_signature())
     return self._post("/transactions", {"transaction": params})
 def clone_transaction(self, transaction_id, params):
     Resource.verify_keys(params, Transaction.clone_signature())
     return self._post("/transactions/" + transaction_id + "/clone", {"transaction-clone": params})
Esempio n. 32
0
 def create(self, params):
     Resource.verify_keys(params, Transaction.create_signature())
     self.__check_for_deprecated_attributes(params)
     return self._post("/transactions", {"transaction": params})
Esempio n. 33
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 "granted_payment_instrument_update" in node_wrapper:
            self.granted_payment_instrument_update = GrantedPaymentInstrumentUpdate(
                gateway, node_wrapper["granted_payment_instrument_update"])
        elif attributes["kind"] in [
                WebhookNotification.Kind.GrantedPaymentMethodRevoked,
                WebhookNotification.Kind.PaymentMethodRevokedByCustomer
        ]:
            self.revoked_payment_method_metadata = RevokedPaymentMethodMetadata(
                gateway, node_wrapper)
        elif "local_payment" in node_wrapper and attributes[
                "kind"] == WebhookNotification.Kind.LocalPaymentCompleted:
            self.local_payment_completed = LocalPaymentCompleted(
                gateway, node_wrapper["local_payment"])
        elif "local_payment_reversed" in node_wrapper and attributes[
                "kind"] == WebhookNotification.Kind.LocalPaymentReversed:
            self.local_payment_reversed = LocalPaymentReversed(
                gateway, node_wrapper["local_payment_reversed"])

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

        if "transaction" in attributes:
            self.transaction = Transaction(gateway, attributes.pop("transaction"))