Criação de Pedido - Marjoel/redepay-sdk-php GitHub Wiki

Clique aqui para ver como importar e integrar a SDK em seu projeto.

Requisição

negrito: obrigatório

PARÂMETRO TIPO EXEMPLO
reference string $order->setReference($reference)
discount integer $order->setDiscount($discount)
shipping Shipping $order->setShipping($shipping)
items Item[] $order->setItems($items)
customer Customer $order->setCustomer($customer)
settings Settings $order->setSettings($settings)
urls Url[] $order->setUrls($urls)

Resposta

CAMPO TIPO EXEMPLO
id string $newOrder->getId()
creationDate string $newOrder->getCreationDate()
reference string $newOrder->getReference()

Exemplo

/* Shipping */
$address = new \RedePay\Address\Address();
$address->setAlias("Comercial");
$address->setStreet("Av. Marcos Penteado de Ulhôa Rodrigues");
$address->setNumber("154");
$address->setComplement("Torre Jacarandá");
$address->setPostalCode("06460040");
$address->setDistrict("Tamboré");
$address->setCity("Barueri");
$address->setState("SP");

$shipping = new \RedePay\Shipping\Shipping();
$shipping->setCost(5000); // R$ 50,00
$shipping->setAddress($address);

/* Items */
$item = new \RedePay\Item\Item();
$item->setId("1");
$item->setAmount(500000); // R$ 5.000,00
$item->setQuantity(1);
$item->setDiscount(50000); // R$ 500,00
$item->setDescription("iPhone 7 256GB");
$item->setFreight(5000); // R$ 50,00

$items = array();
$items[] = $item;

/* Customer */
$cellphone = new \RedePay\Phone\Phone();
$cellphone->setKind("cellphone");
$cellphone->setNumber("11999999999");
$phones = array();
$phones[] = $cellphone;

$document = new \RedePay\Document\Document();
$document->setKind("cpf");
$document->setNumber("56442228533");
$documents = array();
$documents[] = $document;

$customer = new \RedePay\Customer\Customer();
$customer->setName("Antonio");
$customer->setEmail("[email protected]");
$customer->setPhones($phones);
$customer->setDocuments($documents);

/* Settings */
$shoppingCartRecovery = new \RedePay\ShoppingCartRecovery\ShoppingCartRecovery();
$shoppingCartRecovery->setEnable(true);
$shoppingCartRecovery->setFirstAlert(12); // horas
$shoppingCartRecovery->setSecondAlert(24); // horas
$shoppingCartRecovery->setThirdAlert(48); // horas
$shoppingCartRecovery->setFourthAlert(72); // horas
$shoppingCartRecovery->setLogoUrl("https://www.minhaloja.com.br/logo");

$settings = new \RedePay\Settings\Settings();
$settings->setExpiresAt("2017-02-01T15:00:00+02:00");
$settings->setMaxInstallments(3);
$settings->setAttempts(1);
$settings->setShoppingCartRecovery($shoppingCartRecovery);

/* Urls */
/* define a URL para qual o comprador será direcionado após concluir a compra */
$redirect = new \RedePay\Url\Url();
$redirect->setKind("redirect");
$redirect->setUrl("https://www.minhaloja.com.br/redirect");

/* define a URL para qual o comprador será direcionado após cancelar a compra */
$cancel = new \RedePay\Url\Url();
$cancel->setKind("cancel");
$cancel->setUrl("https://www.minhaloja.com.br/cancel");

/* define a URL para qual a loja receberá callbacks de alterações status das transações */
$notification = new \RedePay\Url\Url();
$notification->setKind("notification");
$notification->setUrl("https://www.minhaloja.com.br/notification");

/* define a URL para qual a loja receberá callbacks de alterações status dos pedidos */
$orderNotification = new \RedePay\Url\Url();
$orderNotification->setKind("orderNotification");
$orderNotification->setUrl("https://www.minhaloja.com.br/order-notification");

$urls = array();
$urls[] = $redirect;
$urls[] = $cancel;
$urls[] = $notification;
$urls[] = $orderNotification;

$order = new \RedePay\Order\Order();
$order->setReference("1"); 
$order->setDiscount(1000); // R$ 10,00
$order->setShipping($shipping);
$order->setItems($items);
$order->setCustomer($customer);
$order->setSettings($settings);
$order->setUrls($urls);

$newOrder = $RedePay->order()->create($order);