Webpay, I don't think it's very popular, but I'm trying to use it for a while.
The documentation looks easy to understand, but it takes a while to understand after all because it's barely possible.
Python bindings are provided (installable with pip) and are relatively easy to request.
import webpay
client = webpay.WebPay(settings.WEBPAY_SECRET)
response = client.customer.create(card=token)
Like this.
This response
variable contains the webpay ʻEntity type (
webpay.data_types.Entity`), which is similar in content to a dictionary, but each value is expanded into a class variable. I will. It's like a JavaScript object.
It's nested, so trying to log it can be very annoying.
For the time being, __str__
is implemented, and a somewhat structured character string similar to yaml is returned, but it is a little nervous because it includes line breaks and so on. Unless you also write a parser, reusability seems low.
Therefore. If you recursively convert it to a dictionary type, it will be easier to handle.
from webpay.data_types import Entity
def webpay_entity_to_dict(webpay_entity):
"""
Recursively convert webpay Entity type to Dict
"""
if isinstance(webpay_entity, list):
return [webpay_entity_to_dict(e) for e in webpay_entity]
if not isinstance(webpay_entity, Entity):
return webpay_entity
return {key: webpay_entity_to_dict(value) for key, value
in webpay_entity.__dict__.items()}
If you pass this, you can make it a dictionary type, so it will be easier to serialize it, such as json.dumps () and then logging it.
Recommended Posts