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 _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 test_parse_response_returns_a_credit_card(self):
        credit_card = parse_payment_method(BraintreeGateway(None), {
            "credit_card": {"bin": "411111", "last_4": "1111"}
        })

        self.assertEqual(CreditCard, credit_card.__class__)
        self.assertEqual("411111", credit_card.bin)
        self.assertEqual("1111", credit_card.last_4)
    def test_parse_response_returns_a_paypal_account(self):
        paypal_account = parse_payment_method(BraintreeGateway(None), {
            "paypal_account": {"token": "1234", "default": False}
        })

        self.assertEqual(PayPalAccount, paypal_account.__class__)
        self.assertEqual("1234", paypal_account.token)
        self.assertFalse(paypal_account.default)
    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, 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 test_parse_response_returns_a_credit_card(self):
        credit_card = parse_payment_method(
            BraintreeGateway(None),
            {"credit_card": {
                "bin": "411111",
                "last_4": "1111"
            }})

        self.assertEqual(CreditCard, credit_card.__class__)
        self.assertEqual("411111", credit_card.bin)
        self.assertEqual("1111", credit_card.last_4)
    def test_parse_response_returns_a_paypal_account(self):
        paypal_account = parse_payment_method(
            BraintreeGateway(None),
            {"paypal_account": {
                "token": "1234",
                "default": False
            }})

        self.assertEqual(PayPalAccount, paypal_account.__class__)
        self.assertEqual("1234", paypal_account.token)
        self.assertFalse(paypal_account.default)
    def test_parse_response_returns_an_unknown_payment_method(self):
        unknown_payment_method = parse_payment_method(BraintreeGateway(None), {
            "new_fancy_payment_method": {
                "token": "1234",
                "default": True,
                "other_fancy_thing": "is-shiny"
            }
        })

        self.assertEqual(UnknownPaymentMethod, unknown_payment_method.__class__)
        self.assertEqual("1234", unknown_payment_method.token)
        self.assertTrue(unknown_payment_method.default)
 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 _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 "revoke" and response.get("success", False):
         return SuccessfulResult()
     elif result_key is "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 test_parse_response_returns_an_unknown_payment_method(self):
        unknown_payment_method = parse_payment_method(
            BraintreeGateway(None), {
                "new_fancy_payment_method": {
                    "token": "1234",
                    "default": True,
                    "other_fancy_thing": "is-shiny"
                }
            })

        self.assertEqual(UnknownPaymentMethod,
                         unknown_payment_method.__class__)
        self.assertEqual("1234", unknown_payment_method.token)
        self.assertTrue(unknown_payment_method.default)
 def __init__(self, gateway, attributes):
     self.revoked_payment_method = parse_payment_method(gateway, attributes)
     self.customer_id = self.revoked_payment_method.customer_id
     self.token = self.revoked_payment_method.token
 def __init__(self, gateway, attributes):
     self.revoked_payment_method = parse_payment_method(gateway, attributes)
     self.customer_id = self.revoked_payment_method.customer_id
     self.token = self.revoked_payment_method.token