Beispiel #1
0
def getStatusByFlowOrder(
    apiclient: ApiClient,
    flowOrder: int,
) -> PaymentStatus:
    """Obtiene el estado de un pago previamente creado, el parametro token
    hace referencia a notification id, el cual se recibe luego de procesado
    un pago
    """
    url = f"{apiclient.api_url}/payment/getStatusByFlowOrder"

    params: Dict[str, Any] = {
        "apiKey": apiclient.api_key,
        "flowOrder": flowOrder
    }
    signature = apiclient.make_signature(params)
    params["s"] = signature
    logging.debug("Before Request:" + str(params))
    response = apiclient.get(url, params)

    if response.status_code == 200:
        return PaymentStatus.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #2
0
def createEmail(apiclient: ApiClient,
                payment_data: Dict[str, Any]) -> PaymentResponse:
    """
    Permite generar un cobro por email. Flow emite un email al pagador
    que contiene la información de la Orden de pago y el link de pago
    correspondiente. Una vez que el pagador efectúe el pago, Flow
    notificará el resultado a la página del comercio que se envió en el
    parámetro urlConfirmation.
    """
    url = f"{apiclient.api_url}/payment/createEmail"
    payment = PaymentRequestEmail.from_dict(payment_data)
    if payment.apiKey is None:
        payment.apiKey = apiclient.api_key

    payment.s = apiclient.make_signature(asdict(payment))

    logging.debug("Before Request:" + str(payment))

    response = apiclient.post(url, asdict(payment))

    if response.status_code == 200:
        return PaymentResponse.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #3
0
def create(apiclient: ApiClient, payment_data: Dict[str,
                                                    Any]) -> PaymentResponse:
    """
    Este método permite crear una orden de pago a Flow y recibe como respuesta
    la URL para redirigir el browser del pagador y el token que identifica la
    transacción. La url de redirección se debe formar concatenando los valores
    recibidos en la respuesta de la siguiente forma:

    url + "?token=" +token

    Una vez que el pagador efectúe el pago, Flow notificará el resultado a la
    página del comercio que se envió en el parámetro urlConfirmation.
    """
    url = f"{apiclient.api_url}/payment/create"
    payment = PaymentRequest.from_dict(payment_data)
    if not payment.apiKey:
        payment.apiKey = apiclient.api_key
    payment.s = apiclient.make_signature(asdict(payment))
    logging.debug("Before Request:" + str(payment))
    response = apiclient.post(url, asdict(payment))
    if response.status_code == 200:
        return PaymentResponse.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #4
0
def create(apiclient: ApiClient, refund_data: Dict[str, Any]) -> RefundStatus:
    """
    Este servicio permite crear una orden de reembolso. Una vez que el
    receptor del reembolso acepte o rechaze el reembolso, Flow
    notificará vía POST a la página del comercio identificada en
    urlCallback pasando como parámetro token

    En esta página, el comercio debe invocar el servicio refund/getStatus
    para obtener el estado del reembolso.
    """
    url = f"{apiclient.api_url}/refund/create"
    refund = RefundRequest.from_dict(refund_data)
    if refund.apiKey is None:
        refund.apiKey = apiclient.api_key
    refund.s = apiclient.make_signature(asdict(refund))
    logging.debug("Before Request:" + str(refund))
    response = apiclient.post(url, asdict(refund))
    if response.status_code == 200:
        return RefundStatus.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #5
0
def getPayments(apiclient: ApiClient, payment_info: Dict[str,
                                                         Any]) -> PaymentList:
    """
    Este método permite obtener la lista paginada de pagos recibidos en
    un día.Los objetos pagos de la lista tienen la misma estructura de
    los retornados en los servicios payment/getStatus
    """
    url = f"{apiclient.api_url}/payment/getPayments"

    payment_info["apiKey"] = apiclient.api_key
    signature = apiclient.make_signature(payment_info)
    payment_info["s"] = signature
    logging.debug("Before Request:" + str(payment_info))
    response = apiclient.get(url, payment_info)

    if response.status_code == 200:
        return PaymentList.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #6
0
def getStatus(
    apiclient: ApiClient,
    token: str,
) -> RefundStatus:
    """
    Permite obtener el estado de un reembolso solicitado. Este servicio
    se debe invocar desde la página del comercio que se señaló en el
    parámetro urlCallback del servicio refund/create.
    """
    url = f"{apiclient.api_url}/refund/getStatus"

    params: Dict[str, Any] = {"apiKey": apiclient.api_key, "token": token}
    signature = apiclient.make_signature(params)
    params["s"] = signature
    logging.debug("Before Request:" + str(params))
    response = apiclient.get(url, params)
    if response.status_code == 200:
        return RefundStatus.from_dict(cast(Dict[str, Any], response.json()))
    elif response.status_code == 400:
        raise GenericError(cast(Dict[str, Any], response.json()))
    elif response.status_code == 401:
        raise GenericError(cast(Dict[str, Any], response.json()))
    else:
        raise GenericError({"code": response.status_code, "message": response})
Beispiel #7
0
from typing import Any, Dict
from pyflowcl import Payment
from pyflowcl.Clients import ApiClient
import logging

logging.basicConfig(level=logging.DEBUG)

API_URL = "https://sandbox.flow.cl/api"
API_KEY = "key"
API_SECRET = "secret"

api = ApiClient(API_URL, API_KEY, API_SECRET)
pago: Dict[str, Any] = {
    "subject": "Asunto Email",
    "commerceOrder": "1234",
    "amount": 5000,
    "email": "*****@*****.**",
    "urlConfirmation": "https://mariofix.com",
    "urlReturn": "https://mariofix.com",
}
llamada = Payment.create(api, pago)
print(llamada)
del llamada

llamada = Payment.createEmail(api, pago)
print(llamada)
del llamada

llamada = Payment.getStatus(api, "token")
print(llamada)
del llamada