Beispiel #1
0
 def _post(self, url, params={}, result_key="payment_method"):
     response = self.config.http().post(self.config.base_merchant_path() + url, params)
     if "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
     elif result_key is None:
         return SuccessfulResult()
     else:
         payment_method = self._parse_payment_method(response)
         return SuccessfulResult({result_key: payment_method})
     return response
 def _post(self, url, params={}, result_key="payment_method"):
     response = self.config.http().post(self.config.base_merchant_path() + url, params)
     if "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
     elif result_key == "revoke" and response.get("success", False):
         return SuccessfulResult()
     elif result_key == "payment_method_nonce":
         payment_method_nonce = self._parse_payment_method_nonce(response)
         return SuccessfulResult({result_key: payment_method_nonce})
     else:
         payment_method = parse_payment_method(self.gateway, response)
         return SuccessfulResult({result_key: payment_method})
     return response
    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"])
Beispiel #4
0
 def adjust_authorization(self, transaction_id, amount):
     transaction_params = {"amount": amount}
     response = self.config.http().put(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/adjust_authorization", {"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 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"])
Beispiel #6
0
 def _post(url, params={}):
     response = Http().post(url, params)
     if "transaction" in response:
         return SuccessfulResult(
             {"transaction": Transaction(response["transaction"])})
     elif "api_error_response" in response:
         return ErrorResult(response["api_error_response"])
 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"])
 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 _put(self, url, params={}):
     response = self.config.http().put(self.config.base_merchant_path() + url, params)
     if "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
     else:
         payment_method = parse_payment_method(self.gateway, response)
         return SuccessfulResult({"payment_method": payment_method})
 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")
 def _post(self, url, params={}):
     response = self.config.http().post(url, params)
     if "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
     else:
         payment_method = self._parse_payment_method(response)
         return SuccessfulResult({"payment_method": payment_method})
Beispiel #12
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"])
Beispiel #13
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"])
Beispiel #14
0
 def _post(self, url, params={}):
     response = self.config.http().post(self.config.base_merchant_path() + url, 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"])
     else:
         pass
Beispiel #15
0
    def search(self, *query):
        if isinstance(query[0], list):
            query = query[0]

        self.search_criteria = self.__criteria(query)

        pc = PaginatedCollection(self.__fetch_disputes)
        return SuccessfulResult({"disputes": pc})
    def delete(customer_id, address_id):
        """
        Delete an address, given a customer_id and address_id::

            result = braintree.Address.delete("my_customer_id", "my_address_id")
        """
        Http().delete("/customers/" + customer_id + "/addresses/" + address_id)
        return SuccessfulResult()
 def __create_result(self, response):
     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"])
Beispiel #18
0
 def _post(self, url, params=None):
     if params is None:
         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"])
 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"])
Beispiel #20
0
 def _post(self, url, params={}):
     response = self.config.http().post(url, 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 register_domain(self, domain):
        response = self.config.http().post(
            self.config.base_merchant_path() +
            "/processing/apple_pay/validate_domains", {'url': domain})

        if "response" in response and response["response"]["success"]:
            return SuccessfulResult()
        elif response["api_error_response"]:
            return ErrorResult(self.gateway, response["api_error_response"])
Beispiel #22
0
    def delete(credit_card_token):
        """
        Delete a credit card, given a credit_card_id::

            result = braintree.CreditCard.delete("my_credit_card_id")
        """

        Http().delete("/payment_methods/" + credit_card_token)
        return SuccessfulResult()
 def _put(self, url, params={}):
     response = self.config.http().put(url, params)
     if "merchant_account" in response:
         return SuccessfulResult({
             "merchant_account":
             MerchantAccount(self.gateway, response["merchant_account"])
         })
     elif "api_error_response" in response:
         return ErrorResult(self.gateway, response["api_error_response"])
 def cancel_release(self, transaction_id):
     response = self.config.http().put(
         "/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 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()
 def cancel(self, subscription_id):
     response = self.config.http().put("/subscriptions/" + subscription_id +
                                       "/cancel")
     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"])
Beispiel #27
0
 def update_details(self, transaction_id, params=None):
     if params is None:
         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 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 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"])
Beispiel #30
0
 def void(self, transaction_id):
     response = self.config.http().put(self.config.base_merchant_path() +
                                       "/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"])