Skip to content

Commit

Permalink
Merge pull request #10 from grongor/version-2
Browse files Browse the repository at this point in the history
Introduce new API version.
  • Loading branch information
grongor committed Apr 12, 2016
2 parents 193acaa + 27406ab commit 048e845
Show file tree
Hide file tree
Showing 24 changed files with 844 additions and 311 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/composer.lock
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.PHONY: build clean test
.PHONY: build build-dev clean test

build:
composer install --no-dev

build-dev:
composer install --dev

clean:
rm -rf $(CURDIR)/vendor
rm -f $(CURDIR)/composer.lock

test: build
test: build-dev
$(CURDIR)/vendor/bin/phpunit tests
64 changes: 31 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
Heureka ověřeno PHP API
=======================
Heureka 'Ověřeno zákazníky' PHP API
===================================

[Heureka Ověřeno](http://overeno.heureka.cz/) service API for PHP.
[Heureka Ověřeno zákazníky](http://overeno.heureka.cz/) (ShopCertification) service API client implementation for PHP.

Examples
--------

You can check working examples in the folder `examples` of this repository.

Usage
-----

Initialize Service using [your API key](http://sluzby.heureka.cz/sluzby/certifikat-spokojenosti/):
Initialize class `Heureka\ShopCertification` using
[your API key](http://sluzby.heureka.cz/sluzby/certifikat-spokojenosti/) (you need to log in):

```php
require_once __DIR__ . '/vendor/autoload.php';
$overeno = new \Heureka\Overeno('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
```
SK shops should initialize Heureka Overeno service with second parameter \Heureka\Overeno::LANGUAGE_SK:

$overeno = new \Heureka\Overeno('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', \Heureka\Overeno::LANGUAGE_SK);

Set customer email:

```php
$overeno->setEmail('[email protected]');
$shopCertification = new \Heureka\ShopCertification('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
```

Add product from order - encoded in UTF8 if possible. Service can handle WINDOWS-1250 and ISO-8859-2 if necessary

**Keep in mind that your API key is only yours and it is supposed to be a secret.** Never post your API key to anyone,
never put it into JavaScript or anywhere else. It should live on your server only. If you feel the need to break this
rule then you are doing something wrong - please consult our [support department](http://onas.heureka.cz/kontakty)
prior to any actions.

SK shops should initialize the class with a service parameter in the options:

```php
$overeno->addProduct('Nokia N95');
$options = ['service' => \Heureka\ShopCertification::HEUREKA_SK];
$shopCertification = new \Heureka\ShopCertification('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', $options);
```

Or add multiple products:
Set the customer e-mail address:

```php
// array $products is populated elsewhere by shop application
foreach ($products as $product) {
$overeno->addProduct($product);
}
$shopCertification->setEmail('[email protected]');
```
or/and add products using [item ID](http://sluzby.heureka.cz/napoveda/xml-feed/#ITEM_ID):

Set the customer's order ID (only integers are allowed):

```php
$overeno->addProductItemId('B1234');
$shopCertification->setOrderId(15195618851564);
```

Provide order ID - BIGINT (0 - 18446744073709551615):

Add products which the customer ordered (use IDs which you used in ITEM_ID field of the Heureka XML feed):
```php
$overeno->setOrderId(123456);
$shopCertification->addProductItemId('B1234');
$shopCertification->addProductItemId('15968421');
$shopCertification->addProductItemId('814687');
```

Send the request:
And finally send request to log the order:

```php
$overeno->send();
$shopCertification->logOrder();
```

[View all examples](https://github.com/heureka/heureka-overeno-php-api/tree/master/examples)
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heureka/overenozakazniky",
"description": "Heureka 'Ověřeno zákazníky' service API",
"name": "heureka/overeno-zakazniky",
"description": "Heureka 'Ověřeno zákazníky' (ShopCertification) service API implementation",
"authors": [
{
"name": "Heureka.cz",
Expand All @@ -10,8 +10,11 @@
"require": {
"php": ">=5.4.0"
},
"suggest": {
"ext-curl": "Simplifies the library usage (you don't have to provide your own requester)"
},
"require-dev": {
"phpunit/phpunit": "~4.4.0",
"phpunit/phpunit": "~4.8.0",
"mockery/mockery": "~0.9.4"
},
"autoload": {
Expand Down
73 changes: 36 additions & 37 deletions examples/basic.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

try {
$testingApiKey = '9b011a7086cfc0210cccfbdb7e51aac8'; // USE your own API key!

$language = \Heureka\Overeno::LANGUAGE_CZ; // you can use LANGUAGE_SK as well

$overeno = new \Heureka\Overeno($testingApiKey, $language);

// set customer email - MANDATORY
$overeno->setEmail('[email protected]');

/**
* Products names should be provided in UTF-8 encoding. The service can handle
* WINDOWS-1250 and ISO-8859-2 if necessary
*/
$overeno->addProduct('Nokia N95');

/**
* And/or add products using item ID
*/
$overeno->addProductItemId('B1234');

// add order ID - BIGINT (0 - 18446744073709551615)
$overeno->setOrderId(123456);

// send request
if ($overeno->send()) {
print('Success');
}

} catch (\Heureka\Overeno\Exception $e) {
// handle errors
print $e->getMessage();
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';

try {
// Use your own API key here. And keep it secret!
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$options = [
// Use \Heureka\ShopCertification::HEUREKA_SK if your e-shop is on heureka.sk
'service' => \Heureka\ShopCertification::HEUREKA_CZ,
];

$shopCertification = new \Heureka\ShopCertification($apiKey, $options);

// Set customer email - it is MANDATORY.
$shopCertification->setEmail('[email protected]');

// Set order ID - it helps you track your customers' orders in Heureka shop administration.
$shopCertification->setOrderId(1597884);

// Add products using ITEM_ID (your products ID) - you HAVE TO put in all the products which the customer ordered.
$shopCertification->addProductItemId('165899412');
$shopCertification->addProductItemId('998884614');

// And finally send the order to our service.
$shopCertification->logOrder();

// Everything went well - we are done here.
// You can redirect the customer to some nice page and thank him for the order. :-)

} catch (\Heureka\ShopCertification\Exception $e) {
// Something unexpected happened.
// We can print the message for debug purposes only,
// DO NOT ever do that on your production environment.
var_dump($e->getMessage());
}
5 changes: 0 additions & 5 deletions src/Overeno/CurlException.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Overeno/Exception.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/Overeno/IRequester.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Overeno/InvalidArgumentException.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/Overeno/Requester.php

This file was deleted.

Loading

0 comments on commit 048e845

Please sign in to comment.