示例#1
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"])
示例#2
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'])

        if "errors" in node_wrapper:
            self.errors = ValidationErrorCollection(node_wrapper['errors'])
            self.message = node_wrapper['message']
示例#3
0
 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"])
示例#4
0
 def __init__(self, gateway, attributes):
     if "next_bill_amount" in attributes:
         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 "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]
    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 "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 "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']
示例#6
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"])
示例#7
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']
 def _post(self, url, params={}):
     response = self.config.http().post(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"])
 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")]
 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 find(self, transaction_id):
     try:
         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")
示例#12
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']
 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"])
示例#14
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"])
示例#15
0
    def __init__(self, gateway, attributes):
        Resource.__init__(self, gateway, attributes)

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