Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
ceac0c8
Bumped WC / WP versions
Louise-Krokedil Oct 5, 2023
aac70c8
Bumped WC version
Louise-Krokedil Oct 5, 2023
7822e4c
Bumped WC version
Louise-Krokedil Dec 15, 2023
d76e08f
Bumped WC/WP versions
Louise-Krokedil Dec 15, 2023
901ba0d
Bumped WC version
Louise-Krokedil Jan 22, 2024
cdc156c
Bumped WC version
Louise-Krokedil Jan 22, 2024
73f75cc
bumped wc/wp versions
Louise-Krokedil Mar 1, 2024
d992b7b
bumped wc version
Louise-Krokedil Mar 1, 2024
396c5a8
Merge branch 'main' into develop
MichaelBengtsson Mar 11, 2024
407ec52
Add dependencies folder with gitkeep
MichaelBengtsson Mar 15, 2024
37dece5
Create scoper.inc.php
MichaelBengtsson Mar 15, 2024
098722c
Add Truelayer SDK with php-scoper support
MichaelBengtsson Mar 15, 2024
dfd6abc
Create class-truelayer-http-client.php
MichaelBengtsson Mar 15, 2024
b6da258
Update .gitignore
MichaelBengtsson Mar 15, 2024
7e5f1f1
Update create payment request to use the SDK
MichaelBengtsson Mar 15, 2024
ecf0057
Update refund request to use the SDK
MichaelBengtsson Mar 15, 2024
a55cfcf
Update build_hosted_payment_page_url
MichaelBengtsson Mar 15, 2024
d500e53
Update get payment status request to use the SDK
MichaelBengtsson Mar 15, 2024
1e0db5e
Update the get merchant accounts request to use the SDK
MichaelBengtsson Mar 15, 2024
b5e4afa
Update the base request class to support the SDK
MichaelBengtsson Mar 15, 2024
d1d2cdc
Update the gateway class to use the SDK versions of the objects
MichaelBengtsson Mar 15, 2024
873d9f1
Update the encryption class to the new namespaces from the scoped cla…
MichaelBengtsson Mar 15, 2024
26091cf
Update the api class to use the SDK
MichaelBengtsson Mar 15, 2024
8253f2f
Remove classes that are no longer needed
MichaelBengtsson Mar 15, 2024
2cf495e
Update truelayer-for-woocommerce.php
MichaelBengtsson Mar 15, 2024
8692018
PHPCS compliance
MichaelBengtsson Mar 15, 2024
2fac22f
bump wc/wp version
krokedilmartin Mar 28, 2024
5d358cf
Update scoping and dependency handling to use wpify/scoper
MichaelBengtsson Apr 12, 2024
9ac98e4
Fix bad error title for requests after getting a token, also prevent …
MichaelBengtsson Apr 12, 2024
8e9cecd
Default the banking providers and release channel to truelayer defaults
MichaelBengtsson Apr 12, 2024
4feff81
Update class-truelayer-request-create-payment.php
MichaelBengtsson Apr 12, 2024
8fda552
Update .gitignore
MichaelBengtsson Apr 15, 2024
60a2f7e
PHPCS fixes
MichaelBengtsson Apr 15, 2024
5097f7e
Better error logging for API errors
MichaelBengtsson Apr 15, 2024
c1969e5
Add sodium compat library to scoper patchers
MichaelBengtsson Apr 15, 2024
4551026
Bump truelayer/client to 2.0.0 and min php version to 8.1
MichaelBengtsson Apr 15, 2024
9a723ce
Update readme.dev.txt
MichaelBengtsson Apr 15, 2024
e790541
Update .distignore
MichaelBengtsson Apr 15, 2024
5153c88
Update deploy.yml
MichaelBengtsson Apr 15, 2024
ab589eb
bump wp/wc version
krokedilmartin Apr 29, 2024
dbf6257
wp wc bump after test
krokedilmartin May 16, 2024
b9d6863
bumped WC/WP versions
Louise-Krokedil Jul 2, 2024
db1b553
bumped WC version
Louise-Krokedil Jul 2, 2024
cb5f70c
Update .distignore
MichaelBengtsson Jul 9, 2024
148e2ca
Prevent issue with print error message when it happens during an ajax…
MichaelBengtsson Jul 9, 2024
da32714
Update truelayer/client package to ^2.1
MichaelBengtsson Jul 9, 2024
2a8fa50
Merge branch 'TrueLayer:main' into main
MichaelBengtsson Jul 9, 2024
f1d7ace
Merge branch 'main' into develop-sdk
MichaelBengtsson Jul 9, 2024
47d285a
Update deployment script
MichaelBengtsson Jul 9, 2024
5557c42
Bumped WC/WP versions
Louise-Krokedil Jul 30, 2024
f917371
Bumped WC version
Louise-Krokedil Jul 30, 2024
c0d05f4
bumped WC version
Louise-Krokedil Aug 9, 2024
f8a996a
bumped WC version
Louise-Krokedil Aug 9, 2024
5ca983c
bumped WP/WC versions
Louise-Krokedil Sep 19, 2024
291b645
bumped WC version
Louise-Krokedil Sep 19, 2024
bb870ad
Merge remote-tracking branch 'origin/develop' into develop-sdk
MichaelBengtsson Sep 19, 2024
eb725c6
Merge branch 'main' into develop-sdk
MichaelBengtsson Sep 19, 2024
8d710f9
Add requires plugins header and update copyright year
MichaelBengtsson Sep 25, 2024
2197d8b
Update API request parameters to order instead of order_id
MichaelBengtsson Sep 25, 2024
10a367a
Fix doc comment referencing a different name
MichaelBengtsson Sep 25, 2024
4acad87
Update composer
MichaelBengtsson Sep 25, 2024
324c121
Merge pull request #8 from krokedil/develop-sdk
mntzrr Sep 26, 2024
c0fe38f
wc bump after test
krokedilmartin Oct 3, 2024
49c9d46
Fix failing tests due to incorrect namespace after scoping
MichaelBengtsson Oct 4, 2024
b116550
Fix case on logger class in migration functions
MichaelBengtsson Oct 4, 2024
b43cba7
Bump the PHP version for unit tests
MichaelBengtsson Oct 4, 2024
65203ef
Version 2.0.0
MichaelBengtsson Oct 4, 2024
c58763c
Settings sidebar permalink info
anyakro Nov 4, 2024
e45ba47
Padding adjustment & added link to permalinks
anyakro Nov 8, 2024
bfbc903
Remove logo padding
anyakro Nov 18, 2024
c152e18
Merge pull request #9 from krokedil/develop-settings-sidebar-permalin…
anyakro Nov 20, 2024
6199e5f
bump wc wp version after test
krokedilmartin Nov 21, 2024
345c5de
bump wp/wc version after test
krokedilmartin Dec 5, 2024
63879ca
Bumped WC/WP version after test
Louise-Krokedil Jan 8, 2025
e1cb517
Bumped WC version after test
Louise-Krokedil Jan 8, 2025
b715bd8
create-dev-zip.yml
krokedilmartin Feb 3, 2025
9788d55
change slug
krokedilmartin Feb 3, 2025
930870d
distignore instead of kernelignore
krokedilmartin Feb 3, 2025
ebcbb80
remove run devzip on commit
krokedilmartin Feb 3, 2025
9dc5b6e
Merge pull request #10 from krokedil/main-dev-zip-github-action
MichaelBengtsson Feb 5, 2025
999c207
bump wp/wc versions after test
krokedilmartin Feb 28, 2025
eeefd75
bump wc version after test
krokedilmartin Mar 19, 2025
3251bf0
bump wp vc version after test
krokedilmartin Apr 17, 2025
31bd1e0
bump wp/wc versions after test
krokedilmartin May 14, 2025
d6ac91a
bump wp/wc after test
krokedilmartin May 28, 2025
0bd1cb2
bumped wp/wc version after test
krokedilmartin Aug 12, 2025
9ecf202
bump wc version after test
krokedilmartin Sep 11, 2025
8aa16ae
Bumped WC version after test.
Louise-Krokedil Oct 27, 2025
0edd690
Bumped WC/WP versions after test.
Louise-Krokedil Oct 27, 2025
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
7 changes: 7 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
.gitignore
composer.json
composer.lock
composer-deps.json
composer-deps.lock
/tmp*
scoper.custom.php
docker-compose.phpunit.yml
docker-compose.yml
Dockerfile
Expand All @@ -28,3 +32,6 @@ yarn.lock
/tests
phpunit.xml.dist
.phpunit.result.cache
vendor/**/*
vendor/*
vendor
74 changes: 74 additions & 0 deletions .github/workflows/create-dev-zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Create Dev Zip

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

env:
PLUGIN_SLUG: truelayer-for-woocommerce

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Create composer cache directory
run: mkdir -p ~/.composer/cache

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- name: Install dependencies and build project
run: |
mkdir -p ~/.composer/cache
composer install --prefer-dist --no-progress
npm ci && npm run build

- name: Get branch name and commit hash
id: vars
run: |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
COMMIT_HASH=$(git rev-parse --short HEAD)
ZIP_FILE_NAME="${{ env.PLUGIN_SLUG }}-dev-${BRANCH_NAME}-${COMMIT_HASH}.zip"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
echo "ZIP_FILE_NAME=${ZIP_FILE_NAME}" >> $GITHUB_ENV

- name: Modify version, prepare zip directory, and create zip file
run: |
sed -i "s/^ \* Version: \(.*\)/ \* Version: \1-dev.${BRANCH_NAME}.${COMMIT_HASH}/" ${{ env.PLUGIN_SLUG }}.php
mkdir -p dev-zip-temp/${{ env.PLUGIN_SLUG }}
rsync -av --exclude-from='.distignore' --exclude='dev-zip-temp' . dev-zip-temp/${{ env.PLUGIN_SLUG }}
cd dev-zip-temp
zip -r ../${{ env.ZIP_FILE_NAME }} ${{ env.PLUGIN_SLUG }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_KROKEDIL_PLUGIN_DEV_ZIP }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_KROKEDIL_PLUGIN_DEV_ZIP }}
aws-region: eu-north-1

- name: Upload to S3
run: |
aws s3 cp ${{ env.ZIP_FILE_NAME }} s3://krokedil-plugin-dev-zip/${{ env.ZIP_FILE_NAME }}

- name: Add annotation to workflow run with dev zip url
run: echo "::notice::Dev Zip Url available for 30 days, https://krokedil-plugin-dev-zip.s3.eu-north-1.amazonaws.com/${{ env.ZIP_FILE_NAME }}"
11 changes: 6 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Install Composer dependencies
uses: php-actions/composer@v6
with:
dev: no
php_version: 7.4

# Install all composer packages and build dependencies folder with wpify/scoper.
- name: Composer Install
run: composer install

- name: Build assets and translation files
run: |
npm ci
npm run build

- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@master
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: php-actions/composer@v6
with:
dev: yes
php_version: 7.4
php_version: 8.1

- name: Build assets and translation files
run: |
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ project.properties

node_modules/
vendor

/vendor-bin/**/vendor/
.phpunit.result.cache

dependencies/*
!dependencies/.gitkeep

# OS X metadata
.DS_Store

Expand All @@ -30,3 +33,6 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# tmp folders from scoping.
tmp*
6 changes: 3 additions & 3 deletions assets/css/truelayer-for-woocommerce-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
}

#krokdocs-text-container{
padding: 1em;
padding: 2em;
border: 1px solid #ccc;
width: 350px;
background-color: #f5f5f5;
}

.krokdocs-sidebar-title {
font-size:1.3em;
margin-bottom: 0.5em;
margin: 0 0 0.5em 0;
}

#krokdocs-sidebar-bottom-holder {
padding: 5px 10px 10px 10px;
padding: 5px 0 0 0;
margin-top: 10px;
align-self: flex-end;
flex-direction: column;
Expand Down
4 changes: 4 additions & 0 deletions classes/admin/class-wc-truelayer-banners.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static function settings_sidebar() {
<span class="small-title">Webhook URI:</span><br>
<code><?php echo esc_url( $callback_uri ); ?></code>
</p>
<p class="krokdocs-sidebar-main-text">
<strong>Please make sure that you have enabled pretty permalinks in your WordPress installation.</strong> Otherwise callbacks from TrueLayer back to your store won’t work and orders will not be updated with the correct order status/information.<br>
<a href="https://wordpress.org/documentation/article/customize-permalinks/#pretty-permalinks" target="_blank">What is pretty permalinks?</a>
</p>
<h3 class="krokdocs-sidebar-title">Support</h3>
<p class="krokdocs-sidebar-main-text">
If you have questions regarding a certain purchase you are welcome to contact <a href="https://www.truelayer.com/" target="_blank">TrueLayer</a>.
Expand Down
88 changes: 31 additions & 57 deletions classes/class-truelayer-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,38 @@
exit;
}

use KrokedilTrueLayerDeps\TrueLayer\Interfaces\MerchantAccount\MerchantAccountInterface;
use KrokedilTrueLayerDeps\TrueLayer\Interfaces\Payment\PaymentCreatedInterface;
use KrokedilTrueLayerDeps\TrueLayer\Interfaces\Payment\PaymentRetrievedInterface;
use KrokedilTrueLayerDeps\TrueLayer\Interfaces\Payment\RefundCreatedInterface;

/**
* The TrueLayer API class.
*/
class TrueLayer_API {


/**
* Get a JWT auth token.
* The settings.
*
* @return string
* @var array
*/
public function get_token() {
$token = false === get_transient( 'truelayer_bearer_token' ) ? '' : get_transient( 'truelayer_bearer_token' );

// Decrypt token.
try {
$token = TruelayerEncryption()->decrypt( $token );
} catch ( Exception $e ) {
TrueLayer_Logger::log( sprintf( 'TrueLayer bearer token not encrypted when fetched from transient. Error message: %s', $e->getMessage() ) );
}

if ( empty( $token ) ) {

// Fetch a new token from TrueLayer.
$request = new TrueLayer_Request_Get_Token();
$response = $request->request();
protected $settings;

if ( ! is_wp_error( $response ) && isset( $response['access_token'] ) ) {
$token = $response['access_token'];
// Encrypt token before saving it to db.
try {
$encrypted_token = TruelayerEncryption()->encrypt( $token );
set_transient( 'truelayer_bearer_token', $encrypted_token, $response['expires_in'] );
} catch ( Exception $e ) {
TrueLayer_Logger::log( sprintf( 'TrueLayer bearer token could not be encrypted when saved to db. Error message: %s', $e->getMessage() ) );
}
}
}
return $token;
/**
* TrueLayer_API constructor.
*/
public function __construct() {
$this->settings = get_option( 'woocommerce_truelayer_settings', array() );
}

/**
* Create a TrueLayer payment.
*
* @param int $order_id The WooCommerce Order ID.
* @return mixed
* @param WC_Order|int|WP_Post $order The WooCommerce order, order ID or WP_Post object.
* @return PaymentCreatedInterface|WP_Error
*/
public function create_payment( $order_id ) {
$request = new TrueLayer_Request_Create_Payment( array( 'order_id' => $order_id ) );
public function create_payment( $order ) {
$request = new TrueLayer_Request_Create_Payment( array( 'order' => $order ) );
$response = $request->request();

return $this->check_for_api_error( $response );
Expand All @@ -66,17 +49,17 @@ public function create_payment( $order_id ) {
/**
* Refund Payment via TrueLayer.
*
* @param int $order_id the WooCOmmerce Order ID.
* @param int $amount The amount to be refunded.
* @param string $reason the refund reason.
* @return mixed
* @param WC_Order|int|WP_Post $order The WooCommerce order, order ID or WP_Post object.
* @param int $amount The amount to be refunded.
* @param string $reason the refund reason.
* @return RefundCreatedInterface|WP_Error
*/
public function refund_payment( $order_id, $amount, $reason ) {
public function refund_payment( $order, $amount, $reason ) {
$request = new TrueLayer_Request_Refunds(
array(
'order_id' => $order_id,
'amount' => $amount,
'reason' => $reason,
'order' => $order,
'amount' => $amount,
'reason' => $reason,
)
);
$response = $request->request();
Expand All @@ -88,7 +71,7 @@ public function refund_payment( $order_id, $amount, $reason ) {
* Get the TrueLayer payment status.
*
* @param string $transaction_id The TrueLayer payment ID.
* @return mixed
* @return PaymentRetrievedInterface|WP_Error
*/
public function get_payment_status( $transaction_id ) {
$request = new TrueLayer_Request_Get_Payment_Status( array( 'transaction_id' => $transaction_id ) );
Expand All @@ -98,29 +81,21 @@ public function get_payment_status( $transaction_id ) {
}

/**
* Get the TrueLayer payment status.
* Get the TrueLayer merchant accounts.
*
* @param string $transaction_id The TrueLayer payment ID.
* @return mixed
* @return MerchantAccountInterface[]|WP_Error
*/
public function get_merchant_accounts( $transaction_id ) {
$request = new TrueLayer_Get_Merchant_Account( array( 'transaction_id' => $transaction_id ) );
public function get_merchant_accounts() {
$request = new TrueLayer_Get_Merchant_Accounts( array() );
$response = $request->request();

foreach ( $response['items'] as $truelayer_item ) {

if ( 'GBP' === $truelayer_item['currency'] ) {
update_post_meta( $transaction_id, '_truelayer_merchant_account_id', $truelayer_item['id'] );
}
}

return $this->check_for_api_error( $response );
}

/**
* Checks for WP Errors and returns either the response as array or a false.
*
* @param array $response The response from the request.
* @param object|WP_Error $response The response from the request.
* @return mixed
*/
private function check_for_api_error( $response ) {
Expand All @@ -131,5 +106,4 @@ private function check_for_api_error( $response ) {
}
return $response;
}

}
23 changes: 10 additions & 13 deletions classes/class-truelayer-encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* @package TrueLayer/Classes/
*/

use Defuse\Crypto\Crypto;
use Defuse\Crypto\Exception\BadFormatException;
use Defuse\Crypto\Exception\EnvironmentIsBrokenException;
use Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException;
use Defuse\Crypto\Key;
use KrokedilTrueLayerDeps\Defuse\Crypto\Crypto;
use KrokedilTrueLayerDeps\Defuse\Crypto\Exception\BadFormatException;
use KrokedilTrueLayerDeps\Defuse\Crypto\Exception\EnvironmentIsBrokenException;
use KrokedilTrueLayerDeps\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException;
use KrokedilTrueLayerDeps\Defuse\Crypto\Key;

/**
* Class Truelayer_Encryption
Expand Down Expand Up @@ -157,7 +157,7 @@ public function decrypt_values( $settings ) {
delete_option( 'truelayer_encryption_error' );

foreach ( $this->encrypted_keys as $encrypted_key ) {
$decrypted_value = $this->decrypt_value( $encrypted_key );
$decrypted_value = $this->decrypt_value( $encrypted_key );

$settings[ $encrypted_key ] = $decrypted_value ? $decrypted_value : '';
}
Expand All @@ -168,7 +168,7 @@ public function decrypt_values( $settings ) {
/**
* Returns the setting with the encrypted values decrypted.
*
* @param string $key The key to decrypt.
* @param string $key The key to decrypt.
* @param string|bool $value The value to decrypt. Pass null to use the value from the settings array.
*
* @return string
Expand Down Expand Up @@ -200,8 +200,7 @@ public function encrypt( $value ) {
if ( defined( 'TRUELAYER_KEY' ) ) {
try {
return Crypto::encrypt( $value, $this->key );
}
catch (EnvironmentIsBrokenException | WrongKeyOrModifiedCiphertextException | BadFormatException $e) {
} catch ( EnvironmentIsBrokenException | WrongKeyOrModifiedCiphertextException | BadFormatException $e ) {
// If the value could not be encrypted, then we should add a error notice to the admin.
$message = __( 'There was an error when encrypting the settings for TrueLayer, please reconfigure the plugin and ensure the settings are saved properly.', 'truelayer-for-woocommerce' );
update_option( 'truelayer_encryption_error', $message, 'no' );
Expand Down Expand Up @@ -229,8 +228,7 @@ public function decrypt( $raw_value ) {
if ( defined( 'TRUELAYER_KEY' ) ) {
try {
return Crypto::decrypt( $raw_value, $this->key );
}
catch (EnvironmentIsBrokenException | WrongKeyOrModifiedCiphertextException | BadFormatException $e) {
} catch ( EnvironmentIsBrokenException | WrongKeyOrModifiedCiphertextException | BadFormatException $e ) {
// If the value could not be decrypted, then we should add a error notice to the admin.
$message = __( 'There was an error when decrypting the settings for TrueLayer, please reconfigure the plugin and ensure the settings are saved properly.', 'truelayer-for-woocommerce' );
update_option( 'truelayer_encryption_error', $message, 'no' );
Expand Down Expand Up @@ -266,8 +264,7 @@ private function get_default_key() {
delete_option( 'truelayer_encryption_key_error' );
try {
return Key::loadFromAsciiSafeString( TRUELAYER_KEY );
}
catch (BadFormatException | EnvironmentIsBrokenException $e) {
} catch ( BadFormatException | EnvironmentIsBrokenException $e ) {
$message = __( 'There was an error when loading the encryption key for TrueLayer, please ensure the encryption key saved in the <code>wp-config.php</code> file as <code>TRUELAYER_KEY</code> has not been modified. To reset delete the definition and add a new key.', 'truelayer-for-woocommerce' );
update_option( 'truelayer_encryption_key_error', $message, 'no' );
return null;
Expand Down
Loading