def create_refund(ran, serialize_format='json', deserialize_format='json', model=None, **kwargs): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['content-type'] = 'application/%s' % serialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/accounts/{0}/refunds".format(ran)) if not model: model = models.Void(**kwargs) if serialize_format == 'json': data = model._obj_to_dict() else: data = model._obj_to_xml() resp, _ = SynHTTPClient().request("POST", endpoint, data=data, headers=headers, sanitize=True) if deserialize_format == 'json': resp_data = resp.json()['papi:refund'] else: resp_data = xmltodict.parse(resp.data())['ns2:refund'] return models.Refund._dict_to_obj(resp_data)
def list_paymentMethods(ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json'): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/accounts/%s/methods" % ran) resp, _ = SynHTTPClient().request("GET", endpoint, headers=headers, sanitize=True) if deserialize_format == 'json': _methods = resp.json()['methods']['method'] else: _methods = xmltodict.parse(resp.data())['ns1:methods'] paymentMethods = {} for m in _methods: _method_obj = models.PaymentMethod._dict_to_obj(m) paymentMethods[_method_obj.methodId] = _method_obj return paymentMethods
def list_payments(ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json'): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/accounts/%s/payments" % ran) resp, _ = SynHTTPClient().request("GET", endpoint, headers=headers, sanitize=True) if deserialize_format == 'json': _payments = resp.json()['payments']['payment'] else: _payments = xmltodict.parse(resp.data())['ns1:payments'] payments = {} for p in _payments: payments[p['id']] = models.Payment._dict_to_obj(p) return payments
def authenticate(endpoint, username, apiKey): headers = {'content-type': 'application/json'} if endpoint.endswith('/v2.0/'): endpoint = '{0}tokens'.format(endpoint) elif endpoint.endswith('/v2.0'): endpoint = '{0}/tokens'.format(endpoint) elif endpoint.endswith('/v2.0/tokens'): pass else: endpoint = '{0}/v2.0/tokens'.format(endpoint) data = {'auth': {"RAX-KSKEY:apiKeyCredentials": {"username": username, "apiKey": apiKey}}} data = json.dumps(data) try: resp, _ = SynHTTPClient().request( "POST", endpoint, headers=headers, data=data, sanitize=True) r = resp.json() except RequestException as e: LOG.debug(e) else: if not r: raise Exception("Failed to authenticate") if 'access' not in r or not r['access']: raise Exception("Failed to parse Auth response Body") return r['access']
def create_methodValidation(lineOfBusiness=None, contractEntity=None, currencyCode=None, addressVerificationInformation=None, method=None, ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json'): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['content-type'] = 'application/%s' % serialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/methodValidations") if addressVerificationInformation: _avi = addressVerificationInformation else: _avi = { 'country': 'US', 'state': 'TX', 'city': 'San Antonio', 'addressLine1': '1 Fanatical Pl', 'addressLine2': '', 'postalCode': '78218', } method = method or get_one_method() if not method.addressVerificationInformation: method.addressVerificationInformation = _avi _mv = models.MethodValidation(method=method, lineOfBusiness=lineOfBusiness or 'US_CLOUD', contractEntity=contractEntity or 'CONTRACT_US', currencyCode=currencyCode or 'USD') if serialize_format == 'json': data = _mv._obj_to_dict() else: data = _mv._obj_to_xml() resp, _ = SynHTTPClient().request("POST", endpoint, data=data, headers=headers, sanitize=True) if deserialize_format == 'json': _data = resp.json()['papi:methodValidation'] else: _data = xmltodict.parse(resp.data())['ns3:methodValidation'] validation = models.MethodValidation._dict_to_obj(_data) methodValidations[validation.methodValidationId] = validation return validation
def authenticate_v2(url, username=None, password=None, tenant_name=None, tenant_id=None, scoped=False, serialize_format="json", deserialize_format="json"): """Creates auth request body and sends it to the given v2 endpoint. :param str username: OpenStack username :param str password: OpenStack password :param str tenant_name: Name of tenant to which the user belongs :param str tenant_id: Id of the tenant :param bool scoped: Flag to retrieve scoped/unscoped tokens :param str serialize_format: Request body format(json/xml) :param str deserialize_format: Response body format(json/xml) """ headers = {} kwargs = {} password_creds = None if url.endswith('/v2.0/'): url = '{0}tokens'.format(url) elif url.endswith('/v2.0'): url = '{0}/tokens'.format(url) else: url = '{0}/v2.0/tokens'.format(url) headers["Content-Type"] = "application/{0}".format(serialize_format) headers["Accept"] = "application/{0}".format(deserialize_format) kwargs["tenant_name"] = tenant_name kwargs["tenant_id"] = tenant_id password_creds = v2.PasswordCredentials(username=username, password=password) if scoped: request_entity = v2.Auth(tenant_name=tenant_name, tenant_id=tenant_id, password_creds=password_creds) else: request_entity = v2.Auth(password_creds=password_creds) data = request_entity.serialize(serialize_format) try: resp, _ = SynHTTPClient().request("POST", url, headers=headers, data=data, sanitize=True) r = resp.json() except RequestException as e: LOG.debug(e) else: if not r: raise Exception("Failed to authenticate") if r['access'] is None: raise Exception("Failed to parse Auth response Body") return r['access']
def authenticate_v2( url, username=None, password=None, tenant_name=None, tenant_id=None, scoped=False, serialize_format="json", deserialize_format="json", ): """Creates auth request body and sends it to the given v2 endpoint. :param str username: OpenStack username :param str password: OpenStack password :param str tenant_name: Name of tenant to which the user belongs :param str tenant_id: Id of the tenant :param bool scoped: Flag to retrieve scoped/unscoped tokens :param str serialize_format: Request body format(json/xml) :param str deserialize_format: Response body format(json/xml) """ headers = {} kwargs = {} password_creds = None if url.endswith("/v2.0/"): url = "{0}tokens".format(url) elif url.endswith("/v2.0"): url = "{0}/tokens".format(url) else: url = "{0}/v2.0/tokens".format(url) headers["Content-Type"] = "application/{0}".format(serialize_format) headers["Accept"] = "application/{0}".format(deserialize_format) kwargs["tenant_name"] = tenant_name kwargs["tenant_id"] = tenant_id password_creds = v2.PasswordCredentials(username=username, password=password) if scoped: request_entity = v2.Auth(tenant_name=tenant_name, tenant_id=tenant_id, password_creds=password_creds) else: request_entity = v2.Auth(password_creds=password_creds) data = request_entity.serialize(serialize_format) try: resp, _ = SynHTTPClient().request("POST", url, headers=headers, data=data, sanitize=True) r = resp.json() except RequestException as e: LOG.debug(e) else: if not r: raise Exception("Failed to authenticate") if r["access"] is None: raise Exception("Failed to parse Auth response Body") return r["access"]
def get_paymentMethod(methodId, ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json'): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin( CONF.syntribos.endpoint, "/v1/accounts/{0}/methods/{1}".format(ran, methodId)) resp, _ = SynHTTPClient().request("GET", endpoint, headers=headers, sanitize=True) m = models.PaymentMethod._dict_to_obj(resp.json()) return m
def create_paymentMethod(methodType, ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json', model=None, **kwargs): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['content-type'] = 'application/%s' % serialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/accounts/{0}/methods".format(ran)) if not model: if 'paymentCard' in methodType: _model_class = models.PaymentCardMethod elif 'electronicCheck' in methodType: _model_class = models.ACHMethod elif 'ukDirectDebit' in methodType: _model_class = models.UKDebitMethod elif 'sepa' in methodType: _model_class = models.SEPAMethod model = _model_class(**kwargs) if serialize_format == 'json': data = model._obj_to_dict() else: data = model._obj_to_xml() resp, _ = SynHTTPClient().request("POST", endpoint, data=data, headers=headers, sanitize=True) if deserialize_format == 'json': resp_data = resp.json()['papi:method'] else: resp_data = xmltodict.parse(resp.data())['ns2:method'] return type(model)._dict_to_obj(resp_data)
def list_voids(ran=CONF.rax_payment_system.ran, serialize_format='json', deserialize_format='json'): headers = {} headers['accept'] = 'application/%s' % deserialize_format headers['x-auth-token'] = get_token() endpoint = urlparse.urljoin(CONF.syntribos.endpoint, "/v1/payments/%s/voids" % get_one_paymentId()) resp, _ = SynHTTPClient().request("GET", endpoint, headers=headers, sanitize=True) if deserialize_format == 'json': _voids = resp.json()['voids']['void'] else: _voids = xmltodict.parse(resp.data())['ns1:voids'] voids = {} for v in _voids: voids[v['id']] = models.Void._dict_to_obj(v) return voids