Skip to content
Permalink
Browse files

feat(ever-admin): complete manage "Merchant" payments settings EV-1231

  • Loading branch information...
AlishMekliov931 committed Jun 24, 2019
1 parent af9aba4 commit 6d14c9f207e3b9a3fff2daf0745c637f154c5195
@@ -1,17 +1,16 @@
import { Component, Input, OnChanges, ViewChild } from '@angular/core';
import { Component, Input, ViewChild } from '@angular/core';
import PaymentGateways, {
paymentGatewaysToString
} from '@modules/server.common/enums/PaymentGateways';
import { Country } from '@modules/server.common/entities';
import { countriesDefaultCurrencies } from '@modules/server.common/entities/Currency';
import { NgForm } from '@angular/forms';
import IPaymentGatewayCreateObject from '@modules/server.common/interfaces/IPaymentGateway';

@Component({
selector: 'ea-payPal-gateway',
templateUrl: './payPal-gateway.component.html'
})
export class PayPalGatewayComponent implements OnChanges {
export class PayPalGatewayComponent {
@ViewChild('payPalConfigForm', { static: true })
payPalConfigForm: NgForm;

@@ -66,15 +65,4 @@ export class PayPalGatewayComponent implements OnChanges {
this.configModel.secretKey = data['secretKey'] || '';
this.configModel.description = data['description'] || '';
}

ngOnChanges(): void {
const merchantCountry = Country[this.warehouseCountry];

if (merchantCountry) {
const defaultCurrency =
countriesDefaultCurrencies[merchantCountry.toString()] || '';

this.configModel.currency = defaultCurrency;
}
}
}
@@ -2,10 +2,8 @@
#stripeGateway
[currenciesCodes]="currenciesCodes"
[companyBrandLogo]="warehouseLogo"
[warehouseCountry]="warehouseCountry"
></ea-stripe-gateway>
<ea-payPal-gateway
#payPalGateway
[currenciesCodes]="currenciesCodes"
[warehouseCountry]="warehouseCountry"
></ea-payPal-gateway>
@@ -1,4 +1,4 @@
import { Component, Input, ViewChild } from '@angular/core';
import { Component, Input, ViewChild, OnChanges } from '@angular/core';
import { Country } from '@modules/server.common/entities';
import { StripeGatewayComponent } from './stripe-gateway/stripe-gateway.component';
import { PayPalGatewayComponent } from './payPal-gateway/payPal-gateway.component';
@@ -7,12 +7,13 @@ import { CurrenciesService } from 'app/@core/data/currencies.service';
import { first } from 'rxjs/operators';
import Warehouse from '@modules/server.common/entities/Warehouse';
import PaymentGateways from '@modules/server.common/enums/PaymentGateways';
import { countriesDefaultCurrencies } from '@modules/server.common/entities/Currency';

@Component({
selector: 'ea-payment-gateways',
templateUrl: './payment-gateways.component.html'
})
export class PaymentGatewaysComponent {
export class PaymentGatewaysComponent implements OnChanges {
@ViewChild('stripeGateway', { static: false })
stripeGateway: StripeGatewayComponent;

@@ -23,6 +24,8 @@ export class PaymentGatewaysComponent {
warehouseLogo: string;
@Input()
warehouseCountry: Country;
@Input()
isEdit: boolean;

currenciesCodes: string[] = [];

@@ -73,6 +76,29 @@ export class PaymentGatewaysComponent {
return paymentsGateways;
}

ngOnChanges(): void {
const merchantCountry = Country[this.warehouseCountry];

if (merchantCountry) {
const defaultCurrency =
countriesDefaultCurrencies[merchantCountry.toString()] || '';

if (
this.stripeGateway &&
(!this.isEdit || !this.stripeGateway.configModel.currency)
) {
this.stripeGateway.configModel.currency = defaultCurrency;
}

if (
this.payPalGateway &&
(!this.isEdit || !this.payPalGateway.configModel.currency)
) {
this.payPalGateway.configModel.currency = defaultCurrency;
}
}
}

private async loadCurrenciesCodes() {
const res = await this.currenciesService
.getCurrencies()
@@ -3,7 +3,6 @@ import PaymentGateways, {
paymentGatewaysToString
} from '@modules/server.common/enums/PaymentGateways';
import { Country } from '@modules/server.common/entities';
import { countriesDefaultCurrencies } from '@modules/server.common/entities/Currency';
import { NgForm } from '@angular/forms';
import IPaymentGatewayCreateObject from '@modules/server.common/interfaces/IPaymentGateway';
import { TranslateService } from '@ngx-translate/core';
@@ -14,7 +13,7 @@ import { Subject } from 'rxjs';
selector: 'ea-stripe-gateway',
templateUrl: './stripe-gateway.component.html'
})
export class StripeGatewayComponent implements OnChanges {
export class StripeGatewayComponent {
@ViewChild('stripeConfigForm', { static: true })
stripeConfigForm: NgForm;

@@ -34,7 +33,9 @@ export class StripeGatewayComponent implements OnChanges {
warehouseCountry: Country;
@Input()
set companyBrandLogo(logo: string) {
this.configModel.companyBrandLogo = logo;
if (!this.configModel.companyBrandLogo) {
this.configModel.companyBrandLogo = logo;
}
}

constructor(private translateService: TranslateService) {
@@ -53,6 +54,7 @@ export class StripeGatewayComponent implements OnChanges {
payButtontext: '',
currency: '',
companyBrandLogo: '',
publishableKey: '',
allowRememberMe: true
};

@@ -82,17 +84,6 @@ export class StripeGatewayComponent implements OnChanges {
};
}

ngOnChanges(): void {
const merchantCountry = Country[this.warehouseCountry];

if (merchantCountry) {
const defaultCurrency =
countriesDefaultCurrencies[merchantCountry.toString()] || '';

this.configModel.currency = defaultCurrency;
}
}

deleteImg() {
this.configModel.companyBrandLogo = '';
}
@@ -102,6 +93,7 @@ export class StripeGatewayComponent implements OnChanges {
this.configModel.payButtontext = data['payButtontext'] || '';
this.configModel.currency = data['currency'] || '';
this.configModel.companyBrandLogo = data['companyBrandLogo'] || '';
this.configModel.publishableKey = data['publishableKey'] || '';
this.configModel.allowRememberMe = data['allowRememberMe'];
}

@@ -13,6 +13,7 @@
<div class="form-group offset-md-2 col-md-8">
<ea-payment-gateways
#paymentGateways
[isEdit]="isEdit"
[warehouseLogo]="warehouseLogo"
[warehouseCountry]="warehouseCountry"
></ea-payment-gateways>
@@ -15,6 +15,8 @@ export class PaymentsSettingsFormComponent {
warehouseLogo: string;
@Input()
warehouseCountry: string;
@Input()
isEdit: boolean;

isPaymentEnabled: boolean = false;

@@ -55,12 +55,12 @@
</google-map>
</nb-tab>

<!-- TODO add translate -->
<!-- TODO load default data [warehouseLogo]="detailsComponent.logo.value"
[warehouseCountry]="locationForm.countryId.value" -->
<nb-tab tabTitle="Payment" class="pt-5">
<ea-warehouse-payments-settings-form
#paymentsSettingsForm
[isEdit]="true"
[warehouseLogo]="detailsComponent.logo.value"
[warehouseCountry]="locationForm.countryId.value"
></ea-warehouse-payments-settings-form>
</nb-tab>

0 comments on commit 6d14c9f

Please sign in to comment.
You can’t perform that action at this time.