CyberSource / CyberSource/cybersource-rest-samples-python

PostCustomerRequest not honoring buyer_information.merchant_customer_id

Abierto
#83 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
29
Forks
34
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When I submit a PostCustomerRequest through CustomerApi the return_data shows the merchant_customer_id as None instead of the value I assigned to it.

Here's the code I'm using to test it:

# ENV_NAME=production python3 console/create_customer.py

import json
import os
import sys
from pathlib import Path

from CyberSource import (
    CustomerApi,
    PostCustomerRequest,
    Tmsv2customersBuyerInformation,
    Tmsv2customersClientReferenceInformation,
    Tmsv2customersMerchantDefinedInformation,
)

from config.cybersource_configuration import (
    CybersourceConfiguration,
)

# Environment (sandbox or production)
ENV_NAME = os.environ.get("ENV_NAME", "sandbox")
dir_path = os.path.dirname(os.path.realpath(__file__))


def del_none(d):
    """
    Delete None values in Input Request Json body
    """
    for key, value in list(d.items()):
        if value is None:
            del d[key]
        elif isinstance(value, dict):
            del_none(value)
    return d


def write_log_audit(status):
    print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}")


buyer_information_merchant_customer_id = "user-1234567890"
buyer_information_email = "user@example.com"
buyer_information = Tmsv2customersBuyerInformation(
    merchant_customer_id=buyer_information_merchant_customer_id,
    email=buyer_information_email,
)

clientReferenceInformationCode = "TC50171_3"
clientReferenceInformation = Tmsv2customersClientReferenceInformation(
    code=clientReferenceInformationCode
)

requestObj = PostCustomerRequest(
    buyer_information=buyer_information.__dict__,
    client_reference_information=clientReferenceInformation.__dict__,
)


requestObj = del_none(requestObj.__dict__)
requestObj = json.dumps(requestObj)

print(requestObj)

try:
    configuration = CybersourceConfiguration()
    client_config = configuration.get_configuration()
    api_instance = CustomerApi(client_config)
    return_data, status, body = api_instance.post_customer(requestObj)

    print("\nAPI RESPONSE CODE : ", status)
    print("\nAPI RESPONSE BODY : ", body)
    print("\nAPI RESPONSE DATA : ", return_data)

    write_log_audit(status)

except Exception as e:
    write_log_audit(str(e))
    print(f"\nException when calling CustomerApi->post_customer: {e}\n")

And here's the response I get back:

❯ python -m console.create_customer

API RESPONSE CODE :  201

API RESPONSE BODY :  {"_links":{"self":{"href":"/tms/v2/customers/41ADA55F0277F548E063AF598E0AFAD3"},"paymentInstruments":{"href":"/tms/v2/customers/41ADA55F0277F548E063AF598E0AFAD3/payment-instruments"},"shippingAddresses":{"href":"/tms/v2/customers/41ADA55F0277F548E063AF598E0AFAD3/shipping-addresses"}},"id":"41ADA55F0277F548E063AF598E0AFAD3","buyerInformation":{"email":"user@example.com"},"clientReferenceInformation":{"code":"TC50171_3"},"metadata":{"creator":"creator_id_here"}}

API RESPONSE DATA :  {'buyer_information': {'email': 'user@example.com',
                       'merchant_customer_id': None},
 'client_reference_information': {'code': 'TC50171_3'},
 'default_payment_instrument': None,
 'default_shipping_address': None,
 'embedded': None,
 'id': '41ADA55F0277F548E063AF598E0AFAD3',
 'links': {'_self': {'href': '/tms/v2/customers/41ADA55F0277F548E063AF598E0AFAD3'},
           'payment_instruments': {'href': '/tms/v2/customers/41ADA55F0277F548E063AF598E0AFAD3/payment-instruments'},
           'shipping_address': None},
 'merchant_defined_information': None,
 'metadata': {'creator': 'creator_id_here'},
 'object_information': None}
[Sample Code Testing] [create_customer] 201

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con console/create_customer.py y reproduce el PostCustomerRequest a través de CustomerApi usando los valores de ejemplo. Compara la solicitud serializada y buyer_information devuelto; se considera terminado cuando merchant_customer_id se envía y se conserva en la respuesta de la API.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.