Compare commits
25 commits
cc881b38a1
...
e171406769
Author | SHA1 | Date | |
---|---|---|---|
e171406769 | |||
724f775121 | |||
5b02ef0b0c | |||
cbc3723814 | |||
8b7172f8ab | |||
4780c64dcf | |||
55520fb41f | |||
1f39c6f8f9 | |||
14bb45cb95 | |||
04ae91b9b7 | |||
d66b956773 | |||
75e83ac339 | |||
d3437974e4 | |||
b6502a3f36 | |||
fda0128767 | |||
f80232d911 | |||
53c3d5e78e | |||
d4cdcd2a9a | |||
da4413af85 | |||
98d9360aad | |||
e78d4efa46 | |||
9f2afbbff9 | |||
21b1866a09 | |||
3936371c97 | |||
7c9b4ef43a |
10 changed files with 404 additions and 108 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -3,7 +3,15 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [1.4.0]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Support for WooComerce:
|
||||||
|
- New tab in Settings to generate authentication token.
|
||||||
|
- Display of WooCommerce credentials for configuration.
|
||||||
|
- New service to interact with WooCommerce-related API endpoints.
|
||||||
|
- A "Return To Shop" button added to ZGo Invoice component
|
||||||
|
|
||||||
## [1.3.2] - 2022-10-11
|
## [1.3.2] - 2022-10-11
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
"budgets": [
|
"budgets": [
|
||||||
{
|
{
|
||||||
"type": "initial",
|
"type": "initial",
|
||||||
"maximumWarning": "500kb",
|
"maximumWarning": "5mb",
|
||||||
"maximumError": "1mb"
|
"maximumError": "10mb"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "anyComponentStyle",
|
"type": "anyComponentStyle",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "zgo",
|
"name": "zgo",
|
||||||
"version": "1.3.2",
|
"version": "1.4.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
|
|
|
@ -117,12 +117,34 @@
|
||||||
mat-raised-button
|
mat-raised-button
|
||||||
(click)="copyAmount()">Copy Amount</button>
|
(click)="copyAmount()">Copy Amount</button>
|
||||||
</div>
|
</div>
|
||||||
|
<button style="margin-top: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
background-color: lightgray;"
|
||||||
|
mat-raised-button
|
||||||
|
(click)="copyMemo()" *ngIf="!isWCOrder">Copy Memo</button>
|
||||||
|
|
||||||
|
<div style="display: flex;
|
||||||
|
justify-content: space-between;"
|
||||||
|
*ngIf="isWCOrder">
|
||||||
<button style="margin-top: 20px;
|
<button style="margin-top: 20px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
background-color: lightgray;"
|
background-color: lightgray;"
|
||||||
mat-raised-button
|
mat-raised-button
|
||||||
(click)="copyMemo()">Copy Memo</button>
|
(click)="copyMemo()">Copy Memo</button>
|
||||||
|
|
||||||
|
<button style="margin-top: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
background-color: lightcyan;"
|
||||||
|
mat-raised-button
|
||||||
|
(click)="backToShop()" >
|
||||||
|
<fa-icon style="color: #FB4F14;
|
||||||
|
margin-bottom: -2px;
|
||||||
|
margin-right: 5px;
|
||||||
|
font-size: 20px;
|
||||||
|
cursor: pointer;"
|
||||||
|
[icon]="faArrowUpRightFromSquare"> </fa-icon>
|
||||||
|
Return to Shop</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
||||||
import { ReceiptService } from '../receipt.service';
|
import { ReceiptService } from '../receipt.service';
|
||||||
import { Order} from '../order/order.model';
|
import { Order} from '../order/order.model';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { faCheck, faHourglass } from '@fortawesome/free-solid-svg-icons';
|
import { faCheck, faHourglass, faArrowUpRightFromSquare } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
import { NotifierService } from '../notifier.service';
|
import { NotifierService } from '../notifier.service';
|
||||||
|
|
||||||
|
@ -17,19 +17,20 @@ var Buffer = require('buffer/').Buffer;
|
||||||
templateUrl: './invoice.component.html',
|
templateUrl: './invoice.component.html',
|
||||||
styleUrls: ['./invoice.component.css']
|
styleUrls: ['./invoice.component.css']
|
||||||
})
|
})
|
||||||
|
|
||||||
export class InvoiceComponent implements OnInit {
|
export class InvoiceComponent implements OnInit {
|
||||||
faCheck = faCheck;
|
faCheck = faCheck;
|
||||||
faHourglass = faHourglass;
|
faHourglass = faHourglass;
|
||||||
|
faArrowUpRightFromSquare = faArrowUpRightFromSquare;
|
||||||
orderId;
|
orderId;
|
||||||
public orderUpdate: Observable<Order>;
|
public orderUpdate: Observable<Order>;
|
||||||
public nameUpdate: Observable<string>;
|
public nameUpdate: Observable<string>;
|
||||||
name: string = '';
|
name: string = '';
|
||||||
error: boolean = false;
|
error: boolean = false;
|
||||||
codeString: string = 'Test';
|
codeString: string = 'Test';
|
||||||
|
public isWCOrder : boolean = false;
|
||||||
zcashUrl: SafeUrl = '';
|
zcashUrl: SafeUrl = '';
|
||||||
|
externalURL: string = '';
|
||||||
|
|
||||||
order:Order = {
|
order:Order = {
|
||||||
_id: '',
|
_id: '',
|
||||||
address: '',
|
address: '',
|
||||||
|
@ -60,6 +61,7 @@ export class InvoiceComponent implements OnInit {
|
||||||
private notifierService : NotifierService
|
private notifierService : NotifierService
|
||||||
) {
|
) {
|
||||||
this.orderId = this._ActiveRoute.snapshot.paramMap.get("orderId");
|
this.orderId = this._ActiveRoute.snapshot.paramMap.get("orderId");
|
||||||
|
console.log('constructor - orderId -> ' + this.orderId);
|
||||||
this.orderUpdate = receiptService.orderUpdate;
|
this.orderUpdate = receiptService.orderUpdate;
|
||||||
this.nameUpdate = receiptService.nameUpdate;
|
this.nameUpdate = receiptService.nameUpdate;
|
||||||
receiptService.getOrderById(this.orderId!).subscribe(response => {
|
receiptService.getOrderById(this.orderId!).subscribe(response => {
|
||||||
|
@ -83,9 +85,11 @@ export class InvoiceComponent implements OnInit {
|
||||||
});
|
});
|
||||||
this.orderUpdate.subscribe(order => {
|
this.orderUpdate.subscribe(order => {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
if ( order.session.substring(0,1) == 'W') {
|
||||||
|
this.isWCOrder = true;
|
||||||
|
}
|
||||||
this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId!)))}`;
|
this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId!)))}`;
|
||||||
this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString);
|
this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString);
|
||||||
|
|
||||||
});
|
});
|
||||||
this.nameUpdate.subscribe(name => {
|
this.nameUpdate.subscribe(name => {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -95,6 +99,25 @@ export class InvoiceComponent implements OnInit {
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backToShop() {
|
||||||
|
if ( this.isWCOrder ) {
|
||||||
|
// console.log('External Invoice -> ' + this.order.externalInvoice );
|
||||||
|
const b64URL:string = this.order.externalInvoice.substring(0,this.order.externalInvoice.indexOf("-"));
|
||||||
|
// console.log('encodedURL -> ' + b64URL );
|
||||||
|
const shopURL: string = Buffer.from(b64URL, 'base64').toString();
|
||||||
|
const tmp_orderid = this.order.externalInvoice.substring(this.order.externalInvoice.indexOf('-')+1);
|
||||||
|
const wc_order_key = tmp_orderid.substring(tmp_orderid.indexOf('-')+1);
|
||||||
|
const wc_orderid = tmp_orderid.substring(0,tmp_orderid.indexOf('-'));
|
||||||
|
// console.log('wc_order_id -> ' + wc_orderid);
|
||||||
|
// console.log('wc_order_key -> ' + wc_order_key);
|
||||||
|
// console.log('new URL -> ' + shopURL + '/checkout/order-received/' + wc_orderid + '/?key=' + wc_order_key);
|
||||||
|
if ( shopURL ) {
|
||||||
|
// console.log('Opening URL....' + shopURL);
|
||||||
|
window.open( shopURL + '/checkout/order-received/' + wc_orderid + '/?key=' + wc_order_key,"_blank");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getIconStyle(order : Order) {
|
getIconStyle(order : Order) {
|
||||||
if( order.paid )
|
if( order.paid )
|
||||||
return "font-size: 14px; color: #72cc50; margin-bottom: -2px;";
|
return "font-size: 14px; color: #72cc50; margin-bottom: -2px;";
|
||||||
|
@ -116,6 +139,7 @@ export class InvoiceComponent implements OnInit {
|
||||||
// console.error("Error", err);
|
// console.error("Error", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
copyAmount() {
|
copyAmount() {
|
||||||
if (!navigator.clipboard) {
|
if (!navigator.clipboard) {
|
||||||
// alert("Copy functionality not supported");
|
// alert("Copy functionality not supported");
|
||||||
|
|
|
@ -45,4 +45,15 @@
|
||||||
color: dodgerblue;
|
color: dodgerblue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small {
|
||||||
|
font-size: 12px;
|
||||||
|
background: #dddddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heading {
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@
|
||||||
<mat-tab *ngIf="proVersion"
|
<mat-tab *ngIf="proVersion"
|
||||||
label="Integrations"
|
label="Integrations"
|
||||||
style="align-items: center;">
|
style="align-items: center;">
|
||||||
|
<mat-tab-group mat-tab-align-tabs="start">
|
||||||
|
<mat-tab label="Xero">
|
||||||
<div class="container" style="margin-bottom: 20px;">
|
<div class="container" style="margin-bottom: 20px;">
|
||||||
<mat-dialog-content [formGroup]="accCodForm">
|
<mat-dialog-content [formGroup]="accCodForm">
|
||||||
<div style="height: 10px;
|
<div style="height: 10px;
|
||||||
|
@ -143,9 +145,6 @@
|
||||||
placeholder="9999999999"
|
placeholder="9999999999"
|
||||||
formControlName="xAcc"
|
formControlName="xAcc"
|
||||||
(keyup)="checkStatus($event)">
|
(keyup)="checkStatus($event)">
|
||||||
<!--
|
|
||||||
(change)="xeroAccCodChanged($event)">
|
|
||||||
-->
|
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -170,5 +169,95 @@
|
||||||
margin-top: 10px;">
|
margin-top: 10px;">
|
||||||
</div>
|
</div>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
|
<mat-tab label="WooCommerce">
|
||||||
|
<div >
|
||||||
|
<div *ngIf="wooOwner == ''" align="center">
|
||||||
|
<button mat-raised-button color="primary" (click)="generateWooToken()">
|
||||||
|
Generate Token
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<table *ngIf="wooOwner != ''">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="heading" style="width: 100%;">Owner:</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div>
|
||||||
|
<textarea disabled
|
||||||
|
style="border: none;
|
||||||
|
outline: none;
|
||||||
|
min-height: 150px;
|
||||||
|
width: 94%;"
|
||||||
|
cdkTextareaAutosize
|
||||||
|
cdkAutosizeMinRows="1"
|
||||||
|
cdkAutosizeMaxRows="3">{{wooOwner}}
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="urlCopyBtn">
|
||||||
|
<a (click)='copyWooOwner()' >
|
||||||
|
<fa-icon [icon]="faCopy"
|
||||||
|
class="copy-button">
|
||||||
|
</fa-icon>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="heading" style="width: 60%;">Token:</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div>
|
||||||
|
<textarea disabled
|
||||||
|
style="border: none;
|
||||||
|
outline: none;
|
||||||
|
min-height: 150px;
|
||||||
|
width: 94%;"
|
||||||
|
cdkTextareaAutosize
|
||||||
|
cdkAutosizeMinRows="1"
|
||||||
|
cdkAutosizeMaxRows="3">{{wooToken}}
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="urlCopyBtn">
|
||||||
|
<a (click)='copyWooToken()' >
|
||||||
|
<fa-icon [icon]="faCopy"
|
||||||
|
class="copy-button">
|
||||||
|
</fa-icon>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="heading" style="width: 60%;">URL:</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div>
|
||||||
|
<textarea disabled
|
||||||
|
style="border: none;
|
||||||
|
outline: none;
|
||||||
|
min-height: 150px;
|
||||||
|
width: 94%;"
|
||||||
|
cdkTextareaAutosize
|
||||||
|
cdkAutosizeMinRows="1"
|
||||||
|
cdkAutosizeMaxRows="3">{{wooUrl}}
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="toolbar" align="center">
|
||||||
|
<button mat-raised-button
|
||||||
|
(click)="close()">
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</mat-tab>
|
||||||
|
</mat-tab-group>
|
||||||
|
</mat-tab>
|
||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { UntypedFormBuilder, Validators, UntypedFormGroup, FormControl } from '@
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Owner } from '../owner.model';
|
import { Owner } from '../owner.model';
|
||||||
import { XeroService } from '../xero.service';
|
import { XeroService } from '../xero.service';
|
||||||
|
import { WoocommerceService } from '../woocommerce.service';
|
||||||
|
|
||||||
import { NotifierService } from '../notifier.service';
|
import { NotifierService } from '../notifier.service';
|
||||||
import { faCopy } from '@fortawesome/free-solid-svg-icons';
|
import { faCopy } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
@ -56,6 +57,13 @@ export class SettingsComponent implements OnInit {
|
||||||
xeroLink: string = '';
|
xeroLink: string = '';
|
||||||
localToken: string = '';
|
localToken: string = '';
|
||||||
clientId: string = '';
|
clientId: string = '';
|
||||||
|
wooOwner: string = '';
|
||||||
|
wooToken: string = '';
|
||||||
|
wooUrl: string = '';
|
||||||
|
wooOwnerUpdate: Observable<string>;
|
||||||
|
wooTokenUpdate: Observable<string>;
|
||||||
|
wooUrlUpdate: Observable<string>;
|
||||||
|
|
||||||
clientIdUpdate: Observable<string>;
|
clientIdUpdate: Observable<string>;
|
||||||
accCodeUpdate: Observable<string>;
|
accCodeUpdate: Observable<string>;
|
||||||
linked2Xero : boolean = false;
|
linked2Xero : boolean = false;
|
||||||
|
@ -65,6 +73,7 @@ export class SettingsComponent implements OnInit {
|
||||||
private notifierService : NotifierService,
|
private notifierService : NotifierService,
|
||||||
private fb: UntypedFormBuilder,
|
private fb: UntypedFormBuilder,
|
||||||
public xeroService: XeroService,
|
public xeroService: XeroService,
|
||||||
|
public wooService: WoocommerceService,
|
||||||
private dialogRef: MatDialogRef<SettingsComponent>,
|
private dialogRef: MatDialogRef<SettingsComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: Owner) {
|
@Inject(MAT_DIALOG_DATA) public data: Owner) {
|
||||||
this.useZats = data.zats;
|
this.useZats = data.zats;
|
||||||
|
@ -102,6 +111,19 @@ export class SettingsComponent implements OnInit {
|
||||||
console.log("xeroAccCod -> [" + this.xeroAccCod + "]");
|
console.log("xeroAccCod -> [" + this.xeroAccCod + "]");
|
||||||
this.accCodForm.get('xAcc')!.setValue(this.xeroAccCod);
|
this.accCodForm.get('xAcc')!.setValue(this.xeroAccCod);
|
||||||
});
|
});
|
||||||
|
this.wooOwnerUpdate = wooService.ownerUpdate;
|
||||||
|
this.wooTokenUpdate = wooService.tokenUpdate;
|
||||||
|
this.wooUrlUpdate = wooService.siteurlUpdate;
|
||||||
|
wooService.getWooToken(this.owner._id!);
|
||||||
|
this.wooOwnerUpdate.subscribe(owData => {
|
||||||
|
this.wooOwner = owData;
|
||||||
|
});
|
||||||
|
this.wooTokenUpdate.subscribe(tkData => {
|
||||||
|
this.wooToken = tkData;
|
||||||
|
});
|
||||||
|
this.wooUrlUpdate.subscribe(uData => {
|
||||||
|
this.wooUrl = uData;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -128,7 +150,7 @@ export class SettingsComponent implements OnInit {
|
||||||
closeIntegration() {
|
closeIntegration() {
|
||||||
if ( (this.xeroAccCod == '') && (this.linked2Xero) )
|
if ( (this.xeroAccCod == '') && (this.linked2Xero) )
|
||||||
this.notifierService
|
this.notifierService
|
||||||
.showNotification("Payment confirmation disabled!!","Close",'warning');
|
.showNotification("Xero Payment confirmation disabled!!","Close",'warning');
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,6 +201,45 @@ export class SettingsComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyWooOwner(){
|
||||||
|
try {
|
||||||
|
navigator.clipboard.writeText(this.wooOwner);
|
||||||
|
this.notifierService.showNotification("Owner ID copied to clipboard", "Close", "success");
|
||||||
|
} catch (err) {
|
||||||
|
this.notifierService.showNotification("Copying not available in your browser", "Close", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
copyWooToken(){
|
||||||
|
try {
|
||||||
|
navigator.clipboard.writeText(this.wooToken);
|
||||||
|
this.notifierService.showNotification("WooCommerce Token copied to clipboard", "Close", "success");
|
||||||
|
} catch (err) {
|
||||||
|
this.notifierService.showNotification("Copying not available in your browser", "Close", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateWooToken(){
|
||||||
|
this.wooService.createWooToken(this.owner._id!).subscribe(responseData => {
|
||||||
|
if (responseData.status == 202) {
|
||||||
|
this.notifierService.showNotification("WooCommerce Token generated!", "Close", "success");
|
||||||
|
this.wooService.getWooToken(this.owner._id!);
|
||||||
|
this.wooOwnerUpdate.subscribe(owData => {
|
||||||
|
this.wooOwner = owData;
|
||||||
|
});
|
||||||
|
this.wooTokenUpdate.subscribe(tkData => {
|
||||||
|
this.wooToken = tkData;
|
||||||
|
});
|
||||||
|
this.wooUrlUpdate.subscribe(uData => {
|
||||||
|
this.wooUrl = uData;
|
||||||
|
});
|
||||||
|
close();
|
||||||
|
} else {
|
||||||
|
this.notifierService.showNotification("WooCommerce Token generation failed.", "Close", "error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
saveAccCod() {
|
saveAccCod() {
|
||||||
|
|
||||||
this.xeroAccCod = this.accCodForm.value.xAcc;
|
this.xeroAccCod = this.accCodForm.value.xAcc;
|
||||||
|
|
16
src/app/woocommerce.service.spec.ts
Normal file
16
src/app/woocommerce.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { WoocommerceService } from './woocommerce.service';
|
||||||
|
|
||||||
|
describe('WoocommerceService', () => {
|
||||||
|
let service: WoocommerceService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(WoocommerceService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
65
src/app/woocommerce.service.ts
Normal file
65
src/app/woocommerce.service.ts
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
|
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
|
import { ConfigData } from './configdata';
|
||||||
|
|
||||||
|
var Buffer = require('buffer/').Buffer;
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class WoocommerceService {
|
||||||
|
beUrl = ConfigData.Be_URL;
|
||||||
|
private reqHeaders: HttpHeaders;
|
||||||
|
private ownerId: string = '';
|
||||||
|
private token: string = '';
|
||||||
|
private siteurl: string = '';
|
||||||
|
private _ownerIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.ownerId);
|
||||||
|
private _tokenUpdated: BehaviorSubject<string> = new BehaviorSubject(this.token);
|
||||||
|
private _siteurlUpdated: BehaviorSubject<string> = new BehaviorSubject(this.siteurl);
|
||||||
|
public readonly ownerUpdate: Observable<string> = this._ownerIdUpdated.asObservable();
|
||||||
|
public readonly tokenUpdate: Observable<string> = this._tokenUpdated.asObservable();
|
||||||
|
public readonly siteurlUpdate: Observable<string> = this._siteurlUpdated.asObservable();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: HttpClient
|
||||||
|
) {
|
||||||
|
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
||||||
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
|
this._ownerIdUpdated.next(Object.assign({}, this).ownerId);
|
||||||
|
this._tokenUpdated.next(Object.assign({}, this).token);
|
||||||
|
this._siteurlUpdated.next(Object.assign({}, this).siteurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
getWooToken(ownerId: string) {
|
||||||
|
const params = new HttpParams().append('ownerid', ownerId);
|
||||||
|
let obs = this.http.get<{ownerid: string, token: string, siteurl: string}>(this.beUrl + 'api/wootoken', {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
obs.subscribe(tokenResponse => {
|
||||||
|
if (tokenResponse.status == 200) {
|
||||||
|
this.ownerId = tokenResponse.body!.ownerid;
|
||||||
|
this.token = tokenResponse.body!.token;
|
||||||
|
this.siteurl = tokenResponse.body!.siteurl;
|
||||||
|
this._ownerIdUpdated.next(Object.assign({}, this).ownerId);
|
||||||
|
this._tokenUpdated.next(Object.assign({}, this).token);
|
||||||
|
this._siteurlUpdated.next(Object.assign({}, this).siteurl);
|
||||||
|
} else {
|
||||||
|
console.log('No WooCommerce token found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return obs;
|
||||||
|
}
|
||||||
|
|
||||||
|
createWooToken(ownerId: string) {
|
||||||
|
const params = new HttpParams().append('ownerid', ownerId);
|
||||||
|
let obs = this.http.post(this.beUrl+'api/wootoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
obs.subscribe(responseData => {
|
||||||
|
if (responseData.status == 202) {
|
||||||
|
console.log('WooToken created.');
|
||||||
|
} else {
|
||||||
|
console.log('WooToken creation failed.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return obs;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue