Skip to content

Commit

Permalink
chore: types and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull committed Aug 22, 2023
1 parent 1e057da commit 715af51
Show file tree
Hide file tree
Showing 39 changed files with 458 additions and 487 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* sjelfull
24 changes: 11 additions & 13 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Bug report
about: Create a bug report to help us improve
name: Bug Report
about: Report an issue or unexpected behavior
title: ''
labels: bug
assignees: sjelfull
Expand All @@ -10,21 +10,19 @@ assignees: sjelfull
**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Steps to reproduce**

**Expected behavior**
A clear and concise description of what you expected to happen.
1.
2.

**Screenshots**
If applicable, add screenshots to help explain your problem.
**Screenshots/Video**

If applicable, add screenshots or videos to help explain your problem.

**Additional info**
- Craft version:
- Craft CMS version:
- Craft Commerce version:
- Vipps for Craft Commerce version:
- PHP version:
- Database driver & version:
- Plugins & versions:
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Feature Request
url: https://github.com/superbigco/craft-vipps/discussions/new?category=ideas
about: Start a new discussion about your idea
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## 1.0.7 - 2021-03-03

> {warning} This release fixes a issue with completed orders not being marked as paid, so upgrading is strongly recommended.
> {warning} This release fixes an issue with completed orders not being marked as paid, so upgrading is strongly recommended.
### Added
- Now sends the `Merchant-Serial-Number` header on all requests by default

### Fixed
- Fixed deprecated shipping methods call
- Fixed exception when capture was happening on status change and a transaction couldn't be found
- Fix wrong JSON response when returning from Vipps and a order already was paid
- Fix wrong JSON response when returning from Vipps and an order already was paid
- Fix wrong method being used to complete order on successful payment. This could lead to orders being marked as not paid.
- Fixed deprecated query builder method
- Fixed type parity when comparing paid amount and order total ([#43](https://github.com/superbigco/craft-vipps/pull/43))
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ This is an overview that shows you where to get the different config values thro

### Callback URLs

Note that all URLs passed to Vipps will have to be publicly available. Vipps will validate the URL, and return an error if its accessible from their servers.
Note that all URLs passed to Vipps will have to be publicly available. Vipps will validate the URL, and return an error if it is accessible from their servers.

## Using Vipps

## Express Checkout Buttons

Vipps allow a customer to check and pay for a order straight in the Vipps out, decreasing the number of steps a customer have to take to finish a order.
Vipps allow a customer to check and pay for an order straight in the Vipps out, decreasing the number of steps a customer have to take to finish an order.

To display a Express Checkout button for a variant:
To display an Express Checkout button for a variant:
```twig
{{ craft.vipps.getExpressFormButton(variant) }}
```

To display a Express Checkout button for a cart:
To display an Express Checkout button for a cart:
```twig
{{ craft.vipps.getExpressFormButton() }}
```
Expand Down
29 changes: 25 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "superbig/craft-vipps",
"description": "Integrate Commerce with Vipps",
"description": "Integrate Craft Commerce 4.0+ with Vipps",
"type": "craft-plugin",
"version": "1.0.8",
"version": "2.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"vipps",
"craft commerce",
"commerce"
"commerce",
"gateway"
],
"support": {
"docs": "https://github.com/superbigco/craft-vipps/blob/master/README.md",
Expand All @@ -23,22 +24,42 @@
"homepage": "https://superbig.co"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "8.0",
"php": "^8.0.2",
"craftcms/cms": "^4.0.0",
"craftcms/commerce": "^4.0.0"
},
"require-dev": {
"craftcms/phpstan": "dev-main",
"craftcms/ecs": "dev-main"
},
"autoload": {
"psr-4": {
"superbig\\vipps\\": "src/"
}
},
"scripts": {
"phpstan": "phpstan analyse --memory-limit=1G",
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix"
},
"extra": {
"name": "Vipps",
"handle": "vipps",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/superbigco/craft-vipps/master/CHANGELOG.md",
"class": "superbig\\vipps\\Vipps"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
},
"platform": {
"php": "8.0.2"
}
}
}
14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
includes:
- %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon
parameters:
level: 5
paths:
- src
scanFiles:
# This file must be added to the project root:
# https://github.com/craftcms/cms/blob/develop/lib/craft/behaviors/CustomFieldBehavior.php
- %currentWorkingDirectory%/lib/craft/behaviors/CustomFieldBehavior.php
bootstrapFiles:
- %currentWorkingDirectory%/bootstrap.php
ignoreErrors:
- '#Call to an undefined method yii\\web\\UrlManager::setRouteParams\(\)#'
34 changes: 28 additions & 6 deletions src/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace superbig\vipps;

use Craft;
use superbig\vipps\records\PaymentRecord;
use superbig\vipps\services\Api;
use superbig\vipps\services\Express;
use superbig\vipps\services\Payments;
Expand All @@ -20,12 +22,12 @@
* @package superbig\vipps
*
* @property Payments $payments
* @property Express $express
* @property Api $api
* @property Express $express
* @property Api $api
*/
trait Services
{
public function initComponents()
public function initComponents(): void
{
$this->setComponents([
'payments' => Payments::class,
Expand All @@ -37,24 +39,44 @@ public function initComponents()
/**
* @return Payments The Payments service
*/
public function getPayments()
public function getPayments(): Payments
{
return $this->get('payments');
}

/**
* @return Api The Api service
*/
public function getApi()
public function getApi(): Api
{
return $this->get('api');
}

/**
* @return Express The Express service
*/
public function getExpress()
public function getExpress(): Express
{
return $this->get('express');
}

/**
* Determine whether our table schema exists or not; this is needed because
* migrations such as the install migration and base_install migration may
* not have been run by the time our init() method has been called
*
* @return bool
*/
public function migrationsAndSchemaReady(): bool
{
$pluginsService = Craft::$app->getPlugins();
if ($pluginsService->isPluginUpdatePending(self::$plugin)) {
return false;
}
if (Craft::$app->db->schema->getTableSchema(PaymentRecord::tableName()) === null) {
return false;
}

return true;
}
}
41 changes: 10 additions & 31 deletions src/Vipps.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use craft\web\UrlManager;
use superbig\vipps\behaviors\TransactionBehavior;
use superbig\vipps\gateways\Gateway;
use superbig\vipps\models\Settings;

use superbig\vipps\variables\VippsVariable;
use yii\base\Event;
Expand All @@ -40,26 +39,19 @@
* @package Vipps
* @since 1.0.0
*
*
* @method Settings getSettings()
*/
class Vipps extends Plugin
{
use Services;

// Static Properties
// =========================================================================

public bool $hasCpSettings = false;
public static Vipps $plugin;

public static $commerceInstalled = false;
public static bool $commerceInstalled = false;
public string $schemaVersion = '1.0.0';

// Public Methods
// =========================================================================


public function init()
public function init(): void
{
parent::init();
self::$plugin = $this;
Expand All @@ -81,28 +73,15 @@ public function init()
);
}

protected function createSettingsModel(): ?Model
{
return new Settings();
}


protected function settingsHtml(): string
{
return Craft::$app->view->renderTemplate(
'vipps/settings',
[
'settings' => $this->getSettings(),
]
);
}

protected function installEventListeners()
protected function installEventListeners(): void
{
$this->installGlobalEventListeners();
// Install our event listeners only if our table schema exists
if ($this->migrationsAndSchemaReady()) {
$this->installGlobalEventListeners();
}
}

public function installGlobalEventListeners()
public function installGlobalEventListeners(): void
{
Event::on(
Gateways::class,
Expand Down Expand Up @@ -157,7 +136,7 @@ function () {
);
}

protected function installSiteEventListeners()
protected function installSiteEventListeners(): void
{
Event::on(
UrlManager::class,
Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/vipps/VippsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VippsAsset extends AssetBundle
// =========================================================================


public function init()
public function init(): void
{
$this->sourcePath = "@superbig/vipps/assetbundles/vipps/dist";

Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/vippsexpress/VippsExpressAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VippsExpressAsset extends AssetBundle
// =========================================================================


public function init()
public function init(): void
{
$this->sourcePath = "@superbig/vipps/assetbundles/vippsexpress/dist";

Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/vippsexpress/dist/js/Vipps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @since 1.0.0
*/
(function() {
var formUrl = '{{ siteUrl('vipps/express/checkout') }}';
const formUrl = '{{ siteUrl('vipps/express/checkout') }}';
var formId = '{{ expressButtonId ~ 'Form' }}';
var $button = document.getElementById('{{ expressButtonId }}');
var clickHandler = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VippsUtilityUtilityAsset extends AssetBundle
// =========================================================================


public function init()
public function init(): void
{
$this->sourcePath = "@superbig/vipps/assetbundles/vippsutilityutility/dist";

Expand Down
Loading

0 comments on commit 715af51

Please sign in to comment.