pagarme / pagarme-core-api-php

Other
0 stars 3 forks source link

Billing Address na criacao de OrderCreditCard #25

Open jhonyjss opened 2 years ago

jhonyjss commented 2 years ago

Ola tudo bem ?

Estou enfrentando dificuldades para criar pagamentos e esta constando como status FALHA por que nao consigo enviar o billing_address.

image

image

poderiam me ajudar a tirar essa duvida ?

obrigado

juniormaciel commented 2 years ago

Olá, tive alguns problemas similares, já experimentou criar o objeto billing_adddress ?

$payments->creditCard->card->billingAddress = new CreateAddressRequest( );

E depois passa os valores onde deixei as aspas "" Atenção para o campo linha_1: // (Número, Rua, e Bairro - Nesta ordem e separados por vírgula) Max: 256 caracteres. demais dados segue a doc; https://docs.pagar.me/reference#criar-endereço-1

$payments->creditCard->card->billingAddress->street = ""; $payments->creditCard->card->billingAddress->number = ""; $payments->creditCard->card->billingAddress->zipCode = ""; $payments->creditCard->card->billingAddress->neighborhood = ""; $payments->creditCard->card->billingAddress->city = ""; $payments->creditCard->card->billingAddress->state = ""; $payments->creditCard->card->billingAddress->country = "BR"; $payments->creditCard->card->billingAddress->complement = ""; $payments->creditCard->card->billingAddress->metadata = null; $payments->creditCard->card->billingAddress->line1 = ""; $payments->creditCard->card->billingAddress->line2 = "";

Na requisição vai ficar assim, claro que com os seus dados preenchidos

"billing_address": { "street": "", "number": "", "complement": "", "zip_code": "", "neighborhood": "", "city": "", "state": "", "country": "", "line_1": "", "line_2": "" } },

Um abraço e até mais.

jhonyjss commented 2 years ago

Fala @juniormaciel beleza ?, infelizmente parece que não deu certo, vou te mostrar meu código

obs: coloquei dados fake aqui no post, porém quando viro a chave para producao, aparece esse erro, no ambiente de teste funciona.

$client = new \PagarmeCoreApiLib\PagarmeCoreApiClient($basicAuthUserName, $basicAuthPassword);

    $customerController = $client->getCustomers();

    $customer = new \PagarmeCoreApiLib\Models\CreateCustomerRequest();
    $customer->name = $holder_name;
    $customer->email = "jhony@gmail.com";
    $customer->document_type = "CPF";
    $customer->document = "33333333333";
    $customer->type = "individual";
    $customer->code = "777";

    $customer->address = new \PagarmeCoreApiLib\Models\CreateAddressRequest();
    $customer->address->street = "375, Av. General Justo, Centro";
    $customer->address->line1 = "375, Av. General Justo, Centro";
    $customer->address->zipCode = "04678002";
    $customer->address->neighborhood = "Gopouva";
    $customer->address->number = "77";
    $customer->address->city = "Sao Paulo";
    $customer->address->state = "SP";
    $customer->address->country = "BR";
    $customer->address->metadata = new \PagarmeCoreApiLib\Models\UpdateMetadataRequest();
    $customer->address->metadata->id = "1234";

    $customer->phones = new \PagarmeCoreApiLib\Models\CreatePhonesRequest();
    $customer->phones->homePhone = new \PagarmeCoreApiLib\Models\CreatePhoneRequest();
    $customer->phones->homePhone->areaCode = "11";
    $customer->phones->homePhone->countryCode = "55";
    $customer->phones->homePhone->number = "58587070";

    $request = new \PagarmeCoreApiLib\Models\CreateCardRequest();

    $request->number = str_replace('.','', $cc_number);
    $request->holderName = $holder_name;
    $request->expMonth = (int)$due_date[0];
    $request->expYear = (int)$due_date[1];
    $request->cvv = $cvv;
    $request->holderDocument = "33333333333";
    // Billing Address;
    $request->billingAddress = new \PagarmeCoreApiLib\Models\CreateAddressRequest();
    $request->billingAddress->line1 = "Rua dona Antonia";
    $request->billingAddress->street = "Rua dona Antonia";
    $request->billingAddress->zipCode = "7021000";
    $request->billingAddress->city = "Guarulhos";
    $request->billingAddress->neighborhood = "Gopouva";
    $request->billingAddress->state = "SP";
    $request->billingAddress->country = "BR";

    $createdCustomer = $customerController->createCustomer($customer);
    $result = $customerController->createCard($createdCustomer->id, $request);

    $orderController = $client->getOrders();

    $creditCard = new \PagarmeCoreApiLib\Models\CreateCreditCardPaymentRequest();
    $creditCard->capture = true;
    $creditCard->installments = 1;
    $creditCard->card = new \PagarmeCoreApiLib\Models\CreateCardRequest();
    $creditCard->card->number = str_replace('.','', $cc_number);
    $creditCard->card->holderName = $holder_name;
    $creditCard->card->expMonth = (int)$due_date[0];
    $creditCard->card->expYear = (int)$due_date[1];
    $creditCard->card->cvv = $cvv;

    $request = new \PagarmeCoreApiLib\Models\CreateOrderRequest();

    $request->items = [new \PagarmeCoreApiLib\Models\CreateOrderItemRequest()];
    $request->items[0]->description = "Encontro com Deus";
    $request->items[0]->quantity = 1;
    $request->items[0]->amount = 100 * 1; // this value should be in cents
    $request->items[0]->code = "777"; // this value should be in cents

    $request->payments = [new \PagarmeCoreApiLib\Models\CreatePaymentRequest()];
    $request->payments[0]->paymentMethod = "credit_card";
    $request->payments[0]->creditCard = $creditCard;
    $request->customer = $customer;

    $result = $orderController->createOrder($request);
    echo json_encode($result, JSON_PRETTY_PRINT);
juniormaciel commented 2 years ago

Fala @jhonyjss , tranquilo

Comparando aqui parece tudo normal, se em teste funciona em produção deveria funcionar também, mais vai saber né...

Comparando com a minha saída aqui, verifiquei apenas alguns detalhes diferentes: $customer->address->street = "375, Av. General Justo, Centro"; deveria ser assim sem o numero e sem o bairro: $customer->address->street = "Av. General Justo";

O bloco Billing Address deve estar dentro do objeto $creditCard->card->billingAddress

$creditCard->card->billingAddress = new \PagarmeCoreApiLib\Models\CreateAddressRequest();
$creditCard->card->billingAddress->line1 = "77,Rua dona Antonia,Gopouva";
$creditCard->card->billingAddress->line2 = ""; //adicionado
$creditCard->card->billingAddress->street = "Rua dona Antonia";
$creditCard->card->billingAddress->number = "77"; //adicionado
$creditCard->card->billingAddress->zipCode = "7021000";
$creditCard->card->billingAddress->city = "Guarulhos";
$creditCard->card->billingAddress->neighborhood = "Gopouva";
$creditCard->card->billingAddress->state = "SP";
$creditCard->card->billingAddress->country = "BR";

Experimenta aí e me fala, um abraço.

jhonyjss commented 2 years ago

@juniormaciel eu abri uma outra issue isso e o mais critico.

https://github.com/pagarme/pagarme-core-api-php/issues/26