def find(self, verification_id): try: if verification_id is None or verification_id.strip() == "": raise NotFoundError() response = self.config.http().get(self.config.base_merchant_path() + "/verifications/" + verification_id) return CreditCardVerification(self.gateway, response["verification"]) except NotFoundError: raise NotFoundError("Verification with id " + repr(verification_id) + " not found")
def find(self, subscription_id): try: if subscription_id == None or subscription_id.strip() == "": raise NotFoundError() response = self.config.http().get("/subscriptions/" + subscription_id) return Subscription(self.gateway, response["subscription"]) except NotFoundError: raise NotFoundError("subscription with id " + subscription_id + " not found")
def find(self, customer_id, address_id): try: if customer_id is None or customer_id.strip() == "" or address_id is None or address_id.strip() == "": raise NotFoundError() response = self.config.http().get("/customers/" + customer_id + "/addresses/" + address_id) return Address(self.gateway, response["address"]) except NotFoundError: raise NotFoundError("address for customer " + customer_id + " with id " + address_id + " not found")
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")
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")
def find(self, merchant_account_id): try: if merchant_account_id == None or merchant_account_id.strip() == "": raise NotFoundError() response = self.config.http().get("/merchant_accounts/" + merchant_account_id) return MerchantAccount(self.gateway, response["merchant_account"]) except NotFoundError: raise NotFoundError("merchant account with id " + merchant_account_id + " not found")
def find(self, customer_id): try: if customer_id == None or customer_id.strip() == "": raise NotFoundError() response = self.config.http().get(self.config.base_merchant_path() + "/customers/" + customer_id) return Customer(self.gateway, response["customer"]) except NotFoundError: raise NotFoundError("customer with id " + repr(customer_id) + " not found")
def find(self, customer_id): try: if customer_id is None or customer_id.strip() == "": raise NotFoundError() response = self.config.http().get("/customers/" + customer_id) return Customer(self.gateway, response["customer"]) except NotFoundError: raise NotFoundError("customer with id " + customer_id + " not found")
def find(self, payment_method_token): try: if payment_method_token == None or payment_method_token.strip() == "": raise NotFoundError() response = self.config.http().get("/payment_methods/any/" + payment_method_token) return self._parse_payment_method(response) except NotFoundError: raise NotFoundError("payment method with token " + payment_method_token + " not found")
def find(self, payment_method_nonce): try: if payment_method_nonce is None or payment_method_nonce.strip() == "": raise NotFoundError() response = self.config.http().get(self.config.base_merchant_path() + "/payment_method_nonces/" + payment_method_nonce) return self._parse_payment_method_nonce(response) except NotFoundError: raise NotFoundError("payment method nonce with id " + repr(payment_method_nonce) + " not found")
def find(self, payment_method_token): try: if payment_method_token is None or payment_method_token.strip() == "": raise NotFoundError() response = self.config.http().get(self.config.base_merchant_path() + "/payment_methods/any/" + payment_method_token) return parse_payment_method(self.gateway, response) except NotFoundError: raise NotFoundError("payment method with token " + repr(payment_method_token) + " not found")
def find(self, paypal_account_token): try: if paypal_account_token is None or paypal_account_token.strip() == "": raise NotFoundError() response = self.config.http().get("/payment_methods/paypal_account/" + paypal_account_token) if "paypal_account" in response: return PayPalAccount(self.gateway, response["paypal_account"]) except NotFoundError: raise NotFoundError("paypal account with token " + paypal_account_token + " not found")
def from_nonce(self, nonce): try: if nonce is None or nonce.strip() == "": raise NotFoundError() response = self.config.http().get("/payment_methods/from_nonce/" + nonce) return CreditCard(self.gateway, response["credit_card"]) except NotFoundError: raise NotFoundError("payment method with nonce " + nonce + " locked, consumed or not found")
def find(self, credit_card_token): try: if credit_card_token is None or credit_card_token.strip() == "": raise NotFoundError() response = self.config.http().get("/payment_methods/credit_card/" + credit_card_token) return CreditCard(self.gateway, response["credit_card"]) except NotFoundError: raise NotFoundError("payment method with token " + credit_card_token + " not found")
def find(self, subscription_id): try: if subscription_id is None or subscription_id.strip() == "": raise NotFoundError() response = self.config.http().get( self.config.base_merchant_path() + "/subscriptions/" + subscription_id) return Subscription(self.gateway, response["subscription"]) except NotFoundError: raise NotFoundError("subscription with id " + repr(subscription_id) + " not found")
def find(self, dispute_id): try: if dispute_id is None or dispute_id.strip() == "": raise NotFoundError() response = self.config.http().get( self.config.base_merchant_path() + "/disputes/" + dispute_id) return Dispute(response["dispute"]) except NotFoundError: raise NotFoundError("dispute with id " + repr(dispute_id) + " not found")
def find_all(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 + "/line_items") if "line_items" in response: return [TransactionLineItem(item) for item in ResourceCollection._extract_as_array(response, "line_items")] else: raise RequestTimeoutError() except NotFoundError: raise NotFoundError("transaction line items with id " + repr(transaction_id) + " not found")
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")
def find(self, customer_id, association_filter_id=None): try: if customer_id is None or customer_id.strip() == "": raise NotFoundError() query_params = "" if association_filter_id: query_params = "?association_filter_id=" + association_filter_id response = self.config.http().get(self.config.base_merchant_path() + "/customers/" + customer_id + query_params) return Customer(self.gateway, response["customer"]) except NotFoundError: raise NotFoundError("customer with id " + repr(customer_id) + " not found")
def find(self, ideal_payment_id): try: if ideal_payment_id is None or ideal_payment_id.strip() == "": raise NotFoundError() response = self.config.http().get( self.config.base_merchant_path() + "/ideal_payments/" + ideal_payment_id) if "ideal_payment" in response: return IdealPayment(self.gateway, response["ideal_payment"]) except NotFoundError: raise NotFoundError("iDEAL payment with token" + repr(ideal_payment_id) + " not found")
def grant(self, payment_method_token, options=None): if payment_method_token is None or not str(payment_method_token).strip(): raise ValueError("payment method token cannot be empty or blank") try: if isinstance(options, bool): options = { "allow_vaulting": options } elif options is None: options = {} self.options = options params = { "payment_method": { "shared_payment_method_token": payment_method_token } } params["payment_method"].update(options), return self._post( "/payment_methods/grant", params, "payment_method_nonce" ) except NotFoundError: raise NotFoundError("payment method with payment_method_token " + repr(payment_method_token) + " not found")
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 finalize(self, dispute_id): try: if dispute_id is None or dispute_id.strip() == "": raise NotFoundError() response = self.config.http().put( self.config.base_merchant_path() + "/disputes/" + dispute_id + "/finalize") if "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"]) else: return SuccessfulResult() except NotFoundError: raise NotFoundError("dispute with id " + repr(dispute_id) + " not found")
def find(self, payment_method_nonce): try: response = self.config.http().get("/payment_method_nonces/" + payment_method_nonce) return self._parse_payment_method_nonce(response) except NotFoundError: raise NotFoundError("payment method nonce with id " + payment_method_nonce + " not found")
def add_text_evidence(self, dispute_id, content_or_request): request = content_or_request if isinstance( content_or_request, dict) else { "content": content_or_request } if dispute_id is None or dispute_id.strip() == "": raise NotFoundError("dispute_id cannot be blank") if request.get("content") is None or request["content"].strip() == "": raise ValueError("content cannot be blank") try: if request.get("sequence_number") is not None: request["sequence_number"] = int(request["sequence_number"]) except ValueError: raise ValueError("sequence_number must be an integer") category = request.get("category", request.get("tag")) if "tag" in request.keys(): warnings.warn("Please use category instead", DeprecationWarning) if category is not None and not isinstance(category, str): raise ValueError("category must be a string") try: response = self.config.http().post( self.config.base_merchant_path() + "/disputes/" + dispute_id + "/evidence", { "evidence": { "comments": request.get("content"), "category": category, "sequence_number": request.get("sequence_number") } }) if "evidence" in response: return SuccessfulResult( {"evidence": DisputeEvidence(response["evidence"])}) elif "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"]) except NotFoundError: raise NotFoundError("Dispute with ID " + repr(dispute_id) + " not found")
def remove_evidence(self, dispute_id, evidence_id): try: if dispute_id is None or dispute_id.strip() == "": raise NotFoundError() if evidence_id is None or evidence_id.strip() == "": raise NotFoundError() response = self.config.http().delete( self.config.base_merchant_path() + "/disputes/" + dispute_id + "/evidence/" + evidence_id) if "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"]) else: return SuccessfulResult() except NotFoundError: raise NotFoundError("evidence with id " + repr(evidence_id) + " for dispute with id " + repr(dispute_id) + " not found")
def add_text_evidence(self, dispute_id, content): try: if dispute_id is None or dispute_id.strip() == "": raise NotFoundError() if content is None or content.strip() == "": raise ValueError("content cannot be blank") response = self.config.http().post( self.config.base_merchant_path() + "/disputes/" + dispute_id + "/evidence", {"comments": content}) if "evidence" in response: return SuccessfulResult( {"evidence": DisputeEvidence(response["evidence"])}) elif "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"]) except NotFoundError: raise NotFoundError("dispute with id " + repr(dispute_id) + " not found")
def find(credit_card_token): """ Find a credit card, given a credit_card_id. This does not return a result object. This will raise a :class:`NotFoundError <braintree.exceptions.not_found_error.NotFoundError>` if the provided credit_card_id is not found. :: credit_card = braintree.CreditCard.find("my_credit_card_id") """ try: response = Http().get("/payment_methods/" + credit_card_token) return CreditCard(response["credit_card"]) except NotFoundError: raise NotFoundError("payment method with token " + credit_card_token + " not found")
def add_file_evidence(self, dispute_id, document_upload_id_or_request): request = document_upload_id_or_request if isinstance( document_upload_id_or_request, dict) else { "document_id": document_upload_id_or_request } try: if dispute_id is None or dispute_id.strip() == "": raise NotFoundError() if request.get("category") is not None and not isinstance( request["category"], str): raise ValueError("category must be a string") if request.get("document_id" ) is None or request["document_id"].strip() == "": raise ValueError("document_id cannot be blank") response = self.config.http().post( self.config.base_merchant_path() + "/disputes/" + dispute_id + "/evidence", { "evidence": { "document_upload_id": request.get("document_id"), "category": request.get("category") } }) if "evidence" in response: return SuccessfulResult( {"evidence": DisputeEvidence(response["evidence"])}) elif "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"]) except NotFoundError: raise NotFoundError("dispute with id " + repr(dispute_id) + " not found")
def revoke(self, payment_method_token): if payment_method_token is None or not str( payment_method_token).strip(): raise ValueError try: return self._post( "/payment_methods/revoke", { "payment_method": { "shared_payment_method_token": payment_method_token } }, "revoke") except NotFoundError: raise NotFoundError("payment method with payment_method_token " + repr(payment_method_token) + " not found")