Skip to content

Commit

Permalink
Administration Injection
Browse files Browse the repository at this point in the history
Check API Credentials and easy Access to Payrexx Support from our Plugin
  • Loading branch information
vekkon committed Apr 6, 2020
1 parent 9d8b90f commit 6069a03
Show file tree
Hide file tree
Showing 24 changed files with 557 additions and 141 deletions.

This file was deleted.

21 changes: 0 additions & 21 deletions PayrexxPaymentGatewaySW6/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions PayrexxPaymentGatewaySW6/README.md

This file was deleted.

10 changes: 6 additions & 4 deletions PayrexxPaymentGatewaySW6/composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "payrexx/shopware-payrexx-gateway",
"name": "payrexx/payment",
"description": "A Shopware plugin to accept payments with Payrexx",
"version": "1.0.0",
"version": "1.0.1",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
{
"name": "Payrexx"
"name": "Payrexx AG",
"homepage": "https://payrexx.com"
}
],
"require": {
"shopware/core": "~6.1.0"
"shopware/core": "^6.1",
"shopware/administration":"^6.1"
},
"autoload": {
"psr-4": {
Expand Down
68 changes: 68 additions & 0 deletions PayrexxPaymentGatewaySW6/src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace PayrexxPaymentGateway\Controller;

use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Component\Routing\Annotation\Route;

use Shopware\Core\Framework\Context;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* @RouteScope(scopes={"api"})
*/
class SettingsController extends AbstractController
{
/**
* @var ContainerInterface
*/
protected $container;

/**
* @var LoggerInterface
*/
protected $logger;

/**
* @param ContainerInterface $container
* @param LoggerInterface $logger
**/
public function __construct(
ContainerInterface $container,
LoggerInterface $logger
) {
$this->container = $container;
$this->logger = $logger;
}

/**
* @Route("/api/v{version}/_action/payrexx_payment/validate-api-credentials", name="api.action.payrexx_payment.validate.api.credentials", methods={"POST"})
* @throws \Payrexx\PayrexxException
*/
public function validateApiCredentials(Request $request, Context $context): JsonResponse
{
require_once dirname(dirname(__DIR__)). '/vendor/autoload.php';
$config = $request->get('credentials', []);

$payrexx = new \Payrexx\Payrexx($config['instanceName'], $config['apiKey']);

$signatureCheck = new \Payrexx\Models\Request\SignatureCheck();

$error = '';
try {
$response = $payrexx->getOne($signatureCheck);
} catch(\Payrexx\PayrexxException $e) {
$error = $e;
}
return new JsonResponse(['credentialsValid' => !$error, 'error' => $error]);

}

}
2 changes: 1 addition & 1 deletion PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class PaymentHandler implements AsynchronousPaymentHandlerInterface
{

const PLUGIN_CONFIG_DOMAIN = 'PayrexxPaymentGateway.config.';
const PLUGIN_CONFIG_DOMAIN = 'PayrexxPaymentGatewaySW6.settings.';

const PAYMENT_MEAN_PREFIX = 'payrexx_payment_';
const BASE_URL = 'payrexx.com';
Expand Down
5 changes: 3 additions & 2 deletions PayrexxPaymentGatewaySW6/src/PayrexxPaymentGatewaySW6.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PayrexxPaymentGatewaySW6 extends Plugin
public function install(InstallContext $context): void
{
$this->addPaymentMethod($context->getContext());
parent::install($context);
}

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ private function setPaymentMethodIsActive(bool $active, Context $context): void
$paymentCriteria = (new Criteria())->addFilter(new EqualsFilter('handlerIdentifier', PaymentHandler::class));
$paymentMethods = $paymentRepository->searchIds($paymentCriteria, Context::createDefaultContext());
if (!empty($paymentMethods->getIds())) {
foreach ($paymentMethods->getIds() as $paymentMethodId) {
foreach ($paymentMethods->getIds() as $paymentMethodId) {
$paymentMethod = [
'id' => $paymentMethodId,
'active' => $active,
Expand Down Expand Up @@ -145,4 +146,4 @@ private function getPaymentMethodId(): ?string

return $paymentIds->getIds()[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { Application } = Shopware;
const ApiService = Shopware.Classes.ApiService;

class PayrexxPaymentSettingsService extends ApiService {
constructor(httpClient, loginService, apiEndpoint = 'payrexx_payment') {
super(httpClient, loginService, apiEndpoint);
}

validateApiCredentials(credentials) {
const headers = this.getBasicHeaders();

return this.httpClient
.post(
`_action/${this.getApiBasePath()}/validate-api-credentials`,
{
credentials: credentials,
},
{
headers: headers
}
)
.then((response) => {
return ApiService.handleResponse(response);
});
}

}

Application.addServiceProvider('PayrexxPaymentSettingsService', (container) => {
const initContainer = Application.getContainer('init');

return new PayrexxPaymentSettingsService(initContainer.httpClient, container.loginService);
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './module/payrexx-payment';
import './api/payrexx-payment-settings.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import template from './sw-settings-index.html.twig';
import './sw-settings.index.scss';

const { Component } = Shopware;

Component.override('sw-settings-index', {
template
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% block sw_settings_content_card_slot_plugins %}
{% parent %}

<sw-settings-item :label="$tc('payrexx-payment.module.title')"
:to="{ name: 'payrexx.payment.index' }"
:backgroundEnabled="false">
<template #icon>
<img class="sw-settings-index__payrexx-icon" :src="'payrexxpaymentgatewaysw6/administration/plugin.png' | asset">
</template>
</sw-settings-item>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.payrexx-context-button__button {
height: 48px;
line-height: 40px;
}

.sw-settings-index__payrexx-icon {
height: 40px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import './extension/sw-settings-index';

import './page/payrexx-settings';

import deDE from './snippet/de_DE.json';
import enGB from './snippet/en_GB.json';


const { Module } = Shopware;

Module.register('payrexx-payment', {
type: 'plugin',
name: 'PayrexxPayment',
title: 'payrexx-payment.module.title',
description: 'payrexx-payment.module.description',
version: '1.0.0',
targetVersion: '1.0.0',
icon: 'default-action-settings',

snippets: {
'de-DE': deDE,
'en-GB': enGB
},

routes: {
index: {
component: 'payrexx-settings',
path: 'index',
meta: {
parentPath: 'sw.settings.index'
}
}
}
});
Loading

0 comments on commit 6069a03

Please sign in to comment.