Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/.github export-ignore
/phpunit.xml export-ignore
/.styleci.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
48 changes: 48 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
laravel: [12, 13]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 12
testbench: 10
- laravel: 13
testbench: 11
exclude:
# Laravel 13 requires PHP 8.3+
- laravel: 13
php: '8.2'

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, json, mbstring
coverage: none

- name: Install dependencies
run: |
composer require "orchestra/testbench:^${{ matrix.testbench }}" --dev --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress

- name: Run tests
run: vendor/bin/phpunit
23 changes: 0 additions & 23 deletions .scrutinizer.yml

This file was deleted.

18 changes: 18 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to `AmazonGiftCode` will be documented in this file.

## Version 2.0 - 2026-06-12

### Added
- Support for Laravel 13.
- Test suite (PHPUnit + Orchestra Testbench) covering config, request signing, response parsing and the public API.
- GitHub Actions CI matrix across Laravel 12/13 on PHP 8.2 to 8.4.

### Changed
- `AWS` and `AmazonGiftCode` now accept an optional `ClientInterface`, allowing the HTTP layer to be substituted (defaults to the existing cURL client, so behavior is unchanged).

### Fixed
- `CreateResponse` and `CreateBalanceResponse` no longer raise an undefined-key error when Amazon returns a body without the `cardInfo` / `availableFunds` keys (for example error responses).

### Removed
- Scrutinizer CI configuration (replaced by GitHub Actions).
- `sempro/phpunit-pretty-print` dev dependency (incompatible with PHPUnit 10+).
- Laravel 11 from the CI matrix and dev dependencies; it is past its security support window and is blocked by Composer's advisory policy. It remains installable for existing users via the `illuminate/support` constraint.

## Version 1.0

### Added
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
"Amazon Incentives API"
],
"require": {
"illuminate/support": "~5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0"
"illuminate/support": "~5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0"
},
"require-dev": {
"phpunit/phpunit": "~7.0|~8.0|^10.5|^11.0",
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3.0|^9.0",
"sempro/phpunit-pretty-print": "^1.0"
"phpunit/phpunit": "^10.5|^11.0|^12.5.12",
"orchestra/testbench": "^10.0|^11.0"
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 11 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
failOnWarning="true"
failOnRisky="true">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
19 changes: 16 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

<a href="https://www.buymeacoffee.com/kamerk22" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kamerk22/AmazonGiftCode/badges/quality-score.png?b=master&s=0c4b7d1a88b4519df2f2a95282ef07c53159aca2)](https://scrutinizer-ci.com/g/kamerk22/AmazonGiftCode/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/kamerk22/AmazonGiftCode/badges/build.png?b=master&s=8971718965afae0299de675bf1a1f68dd051207a)](https://scrutinizer-ci.com/g/kamerk22/AmazonGiftCode/build-status/master)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/kamerk22/AmazonGiftCode/badges/code-intelligence.svg?b=master&s=e4998c2937ca56b1d7fcb0bb71d678b3a151ffc8)](https://scrutinizer-ci.com/code-intelligence)
[![Tests](https://github.com/kamerk22/AmazonGiftCode/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/kamerk22/AmazonGiftCode/actions/workflows/run-tests.yml)
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]

Expand All @@ -14,6 +12,13 @@ AmazonGiftCode is Laravel package for Amazon Gift Codes On Demand (AGCOD). Integ
This package will give you a simplest APIs to Create/Cancel Amazon Gift Code On Demand.


## Requirements

- PHP 8.2 or higher (PHP 8.3+ for Laravel 13)
- Laravel 12 or 13

Older Laravel versions (5 to 11) remain installable, but the test suite and CI target 12 and 13. Laravel 11 and below are past their security support window.

## Installation

You can install this package via Composer.
Expand Down Expand Up @@ -215,6 +220,14 @@ Get the raw JSON response. (original response)
$rawJson = $aws->getRawJson();
```

## Testing

``` bash
$ composer test
```

The test suite runs against Laravel 12 and 13 on PHP 8.2 to 8.4 (Laravel 13 requires PHP 8.3+).

## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.
Expand Down
14 changes: 12 additions & 2 deletions src/AWS/AWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


use kamerk22\AmazonGiftCode\Client\Client;
use kamerk22\AmazonGiftCode\Client\ClientInterface;
use kamerk22\AmazonGiftCode\Config\Config;
use kamerk22\AmazonGiftCode\Exceptions\AmazonErrors;
use kamerk22\AmazonGiftCode\Response\CancelResponse;
Expand All @@ -35,14 +36,23 @@ class AWS

private $_config;

/**
* @var ClientInterface
*/
private $_client;


/**
* AWS constructor.
*
* @param Config $config
* @param ClientInterface|null $client Optional HTTP client. Defaults to the
* cURL-based Client; inject a fake for testing.
*/
public function __construct(Config $config)
public function __construct(Config $config, ?ClientInterface $client = null)
{
$this->_config = $config;
$this->_client = $client ?: new Client();
}


Expand Down Expand Up @@ -124,7 +134,7 @@ public function makeRequest($payload, $canonicalRequest, $serviceOperation, $dat

$url = 'https://' . $endpoint . '/' . $serviceOperation;
$headers = $this->buildHeaders($payload, $authorizationValue, $dateTimeString, $serviceTarget);
return (new Client())->request($url, $headers, $payload);
return $this->_client->request($url, $headers, $payload);
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/AmazonGiftCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace kamerk22\AmazonGiftCode;

use kamerk22\AmazonGiftCode\AWS\AWS;
use kamerk22\AmazonGiftCode\Client\ClientInterface;
use kamerk22\AmazonGiftCode\Config\Config;
use kamerk22\AmazonGiftCode\Exceptions\AmazonErrors;

Expand All @@ -11,6 +12,11 @@ class AmazonGiftCode

private $_config;

/**
* @var ClientInterface|null
*/
private $_client;

/**
* AmazonGiftCode constructor.
*
Expand All @@ -19,10 +25,13 @@ class AmazonGiftCode
* @param null $partner
* @param null $endpoint
* @param null $currency
* @param ClientInterface|null $client Optional HTTP client. Defaults to the
* cURL-based Client; inject a fake for testing.
*/
public function __construct($key = null, $secret = null, $partner = null, $endpoint = null, $currency = null)
public function __construct($key = null, $secret = null, $partner = null, $endpoint = null, $currency = null, ?ClientInterface $client = null)
{
$this->_config = new Config($key, $secret, $partner, $endpoint, $currency);
$this->_client = $client;
}

/**
Expand All @@ -32,9 +41,9 @@ public function __construct($key = null, $secret = null, $partner = null, $endpo
*
* @throws AmazonErrors
*/
public function buyGiftCard(Float $value, string $creationRequestId = null): Response\CreateResponse
public function buyGiftCard(Float $value, ?string $creationRequestId = null): Response\CreateResponse
{
return (new AWS($this->_config))->getCode($value, $creationRequestId);
return (new AWS($this->_config, $this->_client))->getCode($value, $creationRequestId);
}


Expand All @@ -45,7 +54,7 @@ public function buyGiftCard(Float $value, string $creationRequestId = null): Res
*/
public function cancelGiftCard(string $creationRequestId, string $gcId): Response\CancelResponse
{
return (new AWS($this->_config))->cancelCode($creationRequestId, $gcId);
return (new AWS($this->_config, $this->_client))->cancelCode($creationRequestId, $gcId);
}

/**
Expand All @@ -55,7 +64,7 @@ public function cancelGiftCard(string $creationRequestId, string $gcId): Respons
*/
public function getAvailableFunds(): Response\CreateBalanceResponse
{
return (new AWS($this->_config))->getBalance();
return (new AWS($this->_config, $this->_client))->getBalance();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Response/CreateBalanceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public function parseJsonResponse($jsonResponse): self
if (!is_array($jsonResponse)) {
throw new \RuntimeException('Response must be a scalar value');
}
if (array_key_exists('amount', $jsonResponse['availableFunds'])) {
if (isset($jsonResponse['availableFunds']['amount'])) {
$this->_amount = $jsonResponse['availableFunds']['amount'];
}
if (array_key_exists('currencyCode', $jsonResponse['availableFunds'])) {
if (isset($jsonResponse['availableFunds']['currencyCode'])) {
$this->_currency = $jsonResponse['availableFunds']['currencyCode'];
}
if (array_key_exists('status', $jsonResponse)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Response/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ public function parseJsonResponse($jsonResponse): self
if (array_key_exists('gcClaimCode', $jsonResponse)) {
$this->_claim_code = $jsonResponse['gcClaimCode'];
}
if (array_key_exists('amount', $jsonResponse['cardInfo']['value'])) {
if (isset($jsonResponse['cardInfo']['value']['amount'])) {
$this->_value = $jsonResponse['cardInfo']['value']['amount'];
}
if (array_key_exists('currencyCode', $jsonResponse['cardInfo']['value'])) {
if (isset($jsonResponse['cardInfo']['value']['currencyCode'])) {
$this->_currency = $jsonResponse['cardInfo']['value']['currencyCode'];
}
if (array_key_exists('gcExpirationDate', $jsonResponse)) {
$this->_expiration_date = $jsonResponse['gcExpirationDate'];
}
if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) {
if (isset($jsonResponse['cardInfo']['cardStatus'])) {
$this->_card_status = $jsonResponse['cardInfo']['cardStatus'];
}

Expand Down
Loading
Loading