Skip to content

Commit

Permalink
Retcon "CC" to also mean "Crypto Currencies", add 7 new icons (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Nov 10, 2023
1 parent 5bb6981 commit 8cad31d
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 29 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2']

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

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
tools: composer:v2
extensions: php-imagick
extensions: imagick
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Cache composer dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# CC Icons

This is a PHP class that generates an image based on a
list of supported credit card types. It makes it easy to
get an image showing all supported payment types for a
payment processor.
list of supported credit card or cryptocurrency types.
It makes it easy to get an image showing all supported
payment types for a payment processor.

## Installation

Expand Down Expand Up @@ -42,16 +42,26 @@ to the image that was created. By default, each image is
## List of Supported Icons

Icons should be specified as a single word, case-insensitive
- AMEX
- Dankort
- DinersClub
- Discover
- JCB
- Maestro -- Aliases: `Switch`, `Solo`
- Mastercard -- Alias: `MC`
- PostePay
- UnionPay
- Visa -- Aliases: `Delta`, `UKE`
- Credit Cards:
- `AMEX`
- `Dankort`
- `DinersClub`
- `Discover`
- `JCB`
- `Maestro` -- Aliases: `Switch`, `Solo`
- `Mastercard` -- Alias: `MC`
- `PostePay`
- `UnionPay`
- `Visa` -- Aliases: `Delta`, `UKE`
- Cryptocurrencies:
- `BTC` (Bitcoin)
- `LTC` (Litecoin)
- `BCH` (Bitcoin Cash)
- `BNB` (Binance Coin)
- `ETH` (Ethereum)
- `USDT` (Tether)
- `USDC` (USD Coin)


## Default Layouts

Expand Down
37 changes: 33 additions & 4 deletions src/CCImageMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CCImageMaker
/** @var array */
private $layout;

/* Give every CC icon a constant to reference */
/* Give every CC icon an ID to reference */
const AMEX = 1;
const DANKORT = 2;
const DINERSCLUB = 3;
Expand All @@ -34,8 +34,18 @@ class CCImageMaker
const UNIONPAY = 9;
const VISA = 10;

/* Give every cryptocurrency icon an ID to reference */
const BTC = 1001;
const LTC = 1002;
const BCH = 1003;
const BNB = 1004;
const ETH = 1005;
const USDT = 1006;
const USDC = 1007;

/** Link supported CC string representations to constants */
protected static $cc_strings = [
// Credit Cards
"VISA" => self::VISA,
"MASTERCARD" => self::MASTERCARD,
"MC" => self::MASTERCARD,
Expand All @@ -50,11 +60,21 @@ class CCImageMaker
"AMEX" => self::AMEX,
"JCB" => self::JCB,
"UNIONPAY" => self::UNIONPAY,
"POSTEPAY" => self::POSTEPAY // Italian Post Office
"POSTEPAY" => self::POSTEPAY, // Italian Post Office

// Cryptocurrencies
"BTC" => self::BTC,
"LTC" => self::LTC,
"BCH" => self::BCH,
"BNB" => self::BNB,
"ETH" => self::ETH,
"USDT" => self::USDT,
"USDC" => self::USDC,
];

/** Link credit cards to their file name in src/icons/ */
/** Link IDs to their file name in src/icons/ */
protected static $supported_cc_types = [
// Credit Cards
self::AMEX => "amex",
self::DANKORT => "dankort",
self::DINERSCLUB => "dinersclub",
Expand All @@ -64,7 +84,16 @@ class CCImageMaker
self::MASTERCARD => "mastercard",
self::POSTEPAY => "postepay",
self::UNIONPAY => "unionpay",
self::VISA => "visa"
self::VISA => "visa",

// Cryptocurrencies
self::BTC => "btc",
self::LTC => "ltc",
self::BCH => "bch",
self::BNB => "bnb",
self::ETH => "eth",
self::USDT => "usdt",
self::USDC => "usdc",
];

/** Width/height of the icon files in src/icons, must be divisible by 4 */
Expand Down
Binary file added src/icons/bch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/bnb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/btc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/eth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/ltc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/usdc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/usdt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion tests/CCImageMakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public function makeImageProvider()
[400, 200],
10,
[3 => [3]]
]
],
'Cryptocurrencies LTC and BCH' => [
'cryptocurrencies.png',
[CCImageMaker::LTC, CCImageMaker::BCH],
],
];
}

Expand Down
Binary file added tests/images/cryptocurrencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions tests/regenerate-fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Vectorface\CCIcons\CCImageMaker;

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

$regular_images = [
'1-icon' => ['AMEX'],
Expand All @@ -11,7 +11,8 @@
'4-icon' => ['UNIONPAY', 'DISCOVER', 'MAESTRO', 'AMEX'],
'5-icon' => ['VISA', 'DINERSCLUB', 'AMEX', 'DISCOVER', 'UNIONPAY'],
'6-icon' => ['MASTERCARD', 'JCB', 'MAESTRO', 'UNIONPAY', 'AMEX', 'DISCOVER'],
'empty' => []
'empty' => [],
'cryptocurrencies' => ['LTC', 'BCH'],
];

$special_images = [
Expand All @@ -38,7 +39,7 @@
'size' => [400, 200],
'padding' => 10,
'layout' => [3]
]
],
];

foreach ($regular_images as $filename => $types) {
Expand Down

0 comments on commit 8cad31d

Please sign in to comment.