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 _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})
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 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 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 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"])
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 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 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"])
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 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 _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
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 __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"])
def revoke_access_token(self, access_token): self.config.assert_has_client_credentials() response = self.config.http().post("/oauth/revoke_access_token", {"token": access_token}) if "result" in response and response["result"]["success"]: return SuccessfulResult else: return ErrorResult(self.gateway, "could not revoke access token")
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 _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 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"])
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 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 _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 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"])
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 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 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 generate(self, settlement_date, group_by_custom_field=None): criteria = {"settlement_date": settlement_date} if group_by_custom_field: criteria["group_by_custom_field"] = group_by_custom_field response = self.config.http().post(self.config.base_merchant_path() + '/settlement_batch_summary', {"settlement_batch_summary": criteria}) if "settlement_batch_summary" in response: return SuccessfulResult({"settlement_batch_summary": SettlementBatchSummary(self.gateway, response["settlement_batch_summary"])}) elif "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"])
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"])
def create(self, params): response = self.config.http().post( self.config.base_merchant_path() + "/verifications", {"verification": params}) if "verification" in response: return SuccessfulResult({ "verification": CreditCardVerification(self.gateway, response["verification"]) }) elif "api_error_response" in response: return ErrorResult(self.gateway, response["api_error_response"])
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 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"])