Make a purchase with a credit card with Cielo API

0

I would like to use Cielo's API to make a purchase with a credit card.

For example, I signed up for a product on my Cielo account, I have the product ID, and would like to use Cielo's API to make a purchase with a credit card.

I have the following code:

<?php
$numero = $_POST['numeroCartao'];
$mesAno = $_POST['mesAno'];
$cvv = $_POST['cvv'];
$nome = $_POST['nome'];

And I would like to use Cielo's API to automatically pay for the product, and to return me if the product was successfully paid, or if there was an error, to return the error message.

I searched the internet for sample codes, but found none!

    
asked by anonymous 07.11.2016 / 18:50

1 answer

1

This example was taken from the Sky API documentation itself.

<?php
require 'vendor/autoload.php';

use Cielo\Cielo;
use Cielo\CieloException;
use Cielo\Transaction;
use Cielo\Holder;
use Cielo\PaymentMethod;

$mid = '12345678'; //seu merchant id
$key = 'xxxx'; //sua chave

$cielo = new Cielo($mid, $key, Cielo::TEST);

$holder = $cielo->holder('4551870000000183', 2018, 5, Holder::CVV_INFORMED, 123);
$order = $cielo->order('178148599', 1000);
$paymentMethod = $cielo->paymentMethod(PaymentMethod::VISA, PaymentMethod::CREDITO_A_VISTA);

$transaction = $cielo->transaction($holder,
                                   $order,
                                   $paymentMethod,
                                   'http://localhost/cielo.php',
                                   Transaction::AUTHORIZE_WITHOUT_AUTHENTICATION,
                                   true);

  try {

    $transaction = $cielo->transactionRequest($transaction);

      if ($transaction->getAuthorization()->getLR() == 0)
          printf("Transação autorizada com sucesso. TID=%s\n", $transaction->getTid());

  } catch (CieloException $e) {

      printf("Opz[%d]: %s\n", $e->getCode(), $e->getMessage());

  }

In this line is where you will put the card information: Number, CVV ...

$holder = $cielo->holder('4551870000000183', 2018, 5, Holder::CVV_INFORMED, 123); 

You may be checking out more examples in the gitHub

    
07.11.2016 / 19:07