PHP code example of carllee1983 / ecpay-einvoice-b2c
1. Go to this page and download the library: Download carllee1983/ecpay-einvoice-b2c library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
carllee1983 / ecpay-einvoice-b2c example snippets
use CarlLee\EcPayB2C\EcPayClient;
use CarlLee\EcPayB2C\Operations\Invoice;
use CarlLee\EcPayB2C\DTO\InvoiceItemDto;
$server = 'https://einvoice-stage.ecpay.com.tw';
$merchantId = '2000132';
$hashKey = 'ejCk326UnaZWKisg';
$hashIV = 'q9jcZX8Ib9LM8wYk';
$client = new EcPayClient($server, $hashKey, $hashIV);
$invoice = new Invoice($merchantId, $hashKey, $hashIV);
$invoice->setRelateNumber('YEP' . date('YmdHis'))
->setCustomerEmail('[email protected]')
->setItems([
InvoiceItemDto::fromArray(['name' => '商品範例', 'quantity' => 1, 'unit' => '個', 'price' => 100]),
])
->setSalesAmount(100);
$response = $client->send($invoice);
$data = $response->getData();