From 0c34ce350293df74a3871c589c87143ffeb2e543 Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Mon, 23 Jul 2018 19:08:29 -0400 Subject: [PATCH] Added currency and paypal stuff --- src/app/app.component.ts | 8 +++-- src/app/store/cart/cart.component.html | 22 ++++--------- src/app/store/cart/cart.component.ts | 33 ++++++++++++++----- .../store/products/products.component.html | 2 +- src/index.html | 3 +- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 29e41d0..c89e335 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -14,7 +14,7 @@ import {LocalStorage} from 'webstorage-decorators'; }) export class AppComponent implements OnInit { @LocalStorage({defaultValue: []}) - cart: {id: string; item: string; price: number; quantity: number}[]; + cart: {id: string; item: string; price: number; currency: 'CAD' | 'USD'; quantity: number}[]; categories; user; @@ -29,8 +29,10 @@ export class AppComponent implements OnInit { this.categories = this.db.collection('categories').valueChanges(); } - addToCart(id: string, item: string, price: number, quantity: number) { - this.cart = [{id: id, item: item, price: Number(price), quantity: Number(quantity)}].concat(this.cart); + addToCart(id: string, item: string, price: number, currency: 'CAD' | 'USD', quantity: number) { + this.cart = [{id: id, item: item, price: Number(price), currency: currency, quantity: Number(quantity)}].concat( + this.cart + ); } cartItemCount() { diff --git a/src/app/store/cart/cart.component.html b/src/app/store/cart/cart.component.html index fd9a30f..b07e9ac 100644 --- a/src/app/store/cart/cart.component.html +++ b/src/app/store/cart/cart.component.html @@ -14,26 +14,18 @@ {{i + 1}} - {{item.item}} + {{item.item}} {{item.quantity}} - {{item.price | currency}} - - delete + {{item.currency}} {{item.price | currency}} + + -
- - - - - -
- Sub Total: - {{total() | currency}}
- -
+
\ No newline at end of file diff --git a/src/app/store/cart/cart.component.ts b/src/app/store/cart/cart.component.ts index 4f7ba4d..134df7e 100644 --- a/src/app/store/cart/cart.component.ts +++ b/src/app/store/cart/cart.component.ts @@ -10,7 +10,7 @@ import {Router} from '../../../../node_modules/@angular/router'; }) export class CartComponent { @LocalStorage({defaultValue: []}) - cart: {id: string; item: string; price: number; quantity: number}[]; + cart: {id: string; item: string; price: number; curency: 'CAD' | 'USD'; quantity: number}[]; address1: string; address2: string; @@ -20,17 +20,32 @@ export class CartComponent { constructor(private http: Http, private router: Router) {} - async checkout() { - let cart = this.cart.map(row => { - return {id: row.id, quantity: row.quantity}; - }); - let link = await this.http - .post('https://us-central1-fhsons-7e90b.cloudfunctions.net/checkout', {cart: cart}) - .toPromise(); - window.location.href = link.url; + ngOnInit() { + if (this.cart.length > 0) { + window['paypal'].Button.render( + { + env: 'sandbox', + client: { + sandbox: 'AejQ8-4hWWWhg1gYKbcuimT8Nf6-wutpEfYBHDDXiEXdujwJzHt6szwtmXBe2d3zW9d3khb3TgQBZUUJ', + live: 'AUhKVWkqvpzRBg0n_IFPMNi9QAl4JCXuWzc04BERDpBdG5ixFH1SimU85I9YSaksqKNCFjp_fOd4OAdd' + }, + style: {size: 'medium', color: 'blue', shape: 'pill'}, + payment: function(data, actions) { + return actions.payment.create({transactions: [{amount: {total: 0.01, currency: 'CAD'}}]}); + }, + onAuthorize: function(data, actions) { + return actions.payment.execute().then(function() { + window.alert('Thank you for your purchase!'); + }); + } + }, + '#paypal-button' + ); + } } remove(i: number) { + console.log('fire'); let c = this.cart; c.splice(i, 1); this.cart = c; diff --git a/src/app/store/products/products.component.html b/src/app/store/products/products.component.html index 329baae..5084457 100644 --- a/src/app/store/products/products.component.html +++ b/src/app/store/products/products.component.html @@ -7,7 +7,7 @@ - diff --git a/src/index.html b/src/index.html index b8add93..6221e4c 100644 --- a/src/index.html +++ b/src/index.html @@ -16,12 +16,13 @@ + + -