Criar uma ordem de pagamento de fatura
Caso de uso
O comerciante cria uma ordem de pagamento de fatura, com uma referência única.
Para pagar, o comprador deve inserir esta referência de fatura exclusiva no formulário de coleta de dados.
Teste
Teste o Web Service Charge/CreatePaymentOrder em nosso playground: Charge/CreatePaymentOrder.
Solicitação
Pagamento à vista
Exemplo de solicitação
Campos obrigatórios:
- Valor: 100,00€.
- Canal de difusão: INVOICE.
- Referência de fatura exclusiva: "myOrderId-1234".
/pt-BR/rest/V4.0/api/kb/authentication.html
https://github.com/lyra/rest-php-examples/blob/master/www/minimalEmbeddedForm.php#L9-L44
https://api.lyra.com/api-payment/V4/Charge/CreatePaymentOrder
{ "amount": 10000, "currency": "EUR", "orderId": "myOrderId-1234", "channelOptions": { "channelType": "INVOICE" } }
{ "amount": 200050, "currency": "PEN", "orderId": "myOrderId-999999", "channelOptions": { "channelType": "INVOICE" }, "paymentReceiptEmail": "sample@example.com", "expirationDate": "2020-04-20T20:13:26+02:00", "locale": "es_PE", "description" : "My custom description" }
{ "amount": 200050, "currency": "ARS", "orderId": "myOrderId-999999", "channelOptions": { "channelType": "INVOICE" }, "paymentReceiptEmail": "sample@example.com", "expirationDate": "2020-04-20T20:13:26+02:00", "locale": "es_AR", "description" : "My custom description" }
{ "amount": 200050, "currency": "COP", "orderId": "myOrderId-999999", "channelOptions": { "channelType": "INVOICE" }, "paymentReceiptEmail": "sample@example.com", "expirationDate": "2020-04-20T20:13:26+02:00", "locale": "es_CO", "description" : "My custom description" }
/** * I initialize the PHP SDK */ require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/keys.php'; require_once __DIR__ . '/helpers.php'; /** * Initialize the SDK * see keys.php */ $client = new Lyra\Client(); /** * I create a formToken */ $store = array("amount" => 250, "currency" => "EUR", "orderId" => uniqid("MyOrderId"), "customer" => array( "email" => "sample@example.com" )); $response = $client->post("V4/Charge/CreatePayment", $store); /* I check if there are some errors */ if ($response['status'] != 'SUCCESS') { /* an error occurs, I throw an exception */ display_error($response); $error = $response['answer']; throw new Exception("error " . $error['errorCode'] . ": " . $error['errorMessage'] ); } /* everything is fine, I extract the formToken */ $formToken = $response["answer"]["formToken"]; ?>
/** * I initialize the PHP SDK */ require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/keys.php'; require_once __DIR__ . '/helpers.php'; /** * Initialize the SDK * see keys.php */ $client = new Lyra\Client(); /** * I create a formToken */ $store = array("amount" => 250, "currency" => "EUR", "orderId" => uniqid("MyOrderId"), "customer" => array( "email" => "sample@example.com" )); $response = $client->post("V4/Charge/CreatePayment", $store); /* I check if there are some errors */ if ($response['status'] != 'SUCCESS') { /* an error occurs, I throw an exception */ display_error($response); $error = $response['answer']; throw new Exception("error " . $error['errorCode'] . ": " . $error['errorMessage'] ); } /* everything is fine, I extract the formToken */ $formToken = $response["answer"]["formToken"]; ?>
O comprador insere a referência única: myOrderId-1234
no formulário de coleta de dados para pagar o valor de € 100,00.
Para conhecer todos os detalhes e descrições dos campos, consulte o playground: Charge/CreatePaymentOrder (menu à esquerda).
Resposta
Exemplo de resposta
{ "webService": "Charge/CreatePaymentOrder", "version": "V4", "applicationVersion": "5.5.0", "status": "SUCCESS", "answer": { "paymentOrderId": "f95a9c6c2d5a4e3ca279401c4d07c115", "paymentURL": null, "paymentOrderStatus": "RUNNING", "creationDate": "2020-03-31T15:06:49+00:00", "updateDate": null, "amount": 10000, "currency": "EUR", "locale": "en_GB", "strongAuthentication": "AUTO", "orderId": "myOrderId-1234", "channelDetails": { "channelType": "INVOICE", "mailDetails": null, "smsDetails": null, "whatsAppDetails": null, "ivrDetails": null, "_type": "V4/ChannelDetails" }, "paymentReceiptEmail": "sample@example.com", "taxRate": null, "taxAmount": null, "expirationDate": "2020-04-20T18:13:26+00:00", "transactionDetails": { "cardDetails": { "manualValidation": "NO", "captureDelay": 0, "_type": "V4/CardDetails" }, "_type": "V4/PaymentOrderTransactionDetails" }, "dataCollectionForm": false, "merchantComment": null, "message": null, "description": "My custom description" "_type": "V4/PaymentOrder" }, "ticket": null, "serverDate": "2020-03-31T15:06:49+00:00", "applicationProvider": "LYRA", "metadata": null, "_type": "V4/WebService/Response" } }
Retrouvez la description et l'intégralité des champs dans notre playground :
Gerenciamento dos erros
Tableau des erreurs
Código | Descrição |
---|---|
Formato do campo amount inválido ou campo não enviado. | |
Formato do campo currency inválido ou campo não enviado. | |
Parâmetro strongAuthentication é inválido. | |
Parâmetro local é inválido. | |
Parâmetro taxRate é inválido. | |
Parâmetro taxAmount é inválido. | |
Moeda desconhecida. | |
Moeda não suportada pelo contrato. | |
A data de validade da ordem de pagamento não pode ser anterior à data de hoje nem ultrapassar um prazo de 90 dias. | |
Nenhum formulário de coleta de dados para esta loja. | |
O formulário de coleta de dados não pode ser usado com a moeda solicitada. |
Análise do resultado do pagamento
Para saber o resultado do pagamento, implemente o URL de notificação no final do pagamento (também conhecido como IPN).
- Informe apenas o URL da notificação na seção API REST (TEST ou PRODUCTION): Procedimento.
- Analisar o IPN: Procedimento.