Skip to content

Commit 816ce2b

Browse files
committed
feat(payment): Support direct cryptocurrency transfers.
1 parent 35a9288 commit 816ce2b

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

src/app/account-app/bitpay-payment-dialog.component.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ <h1 mat-dialog-title>Cryptocurrency payment <img src="/assets/payment/coinbase.s
88
<p>
99
You may now complete your payment via our cryptocurrency payment provider Coinbase.
1010
</p>
11-
<p id="button">
11+
<p class="button">
1212
<button mat-flat-button color="primary"> <a [href]="external_url">Proceed to Coinbase</a>
1313
</button>
1414
</p>
1515
<p>
1616
Processing your payment may take a little while.
1717
You will be notified with an email when the process is finished.
1818
</p>
19+
<p>
20+
If you prefer to transfer cryptocurrency directly you may do so here:
21+
</p>
22+
<p class="button">
23+
<button id="payDirectly" mat-raised-button (click)="initiateCryptoPayment('crypto')" color="primary">
24+
Cryptocurrency Transfer
25+
</button>
26+
</p>
1927
</span>
2028
<span *ngIf="state === 'failed'">
2129
There was an error creating your payment. <br>

src/app/account-app/bitpay-payment-dialog.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ a {
1313
text-decoration: none;
1414
}
1515

16-
#button {
16+
.button {
1717
text-align: center;
1818
}

src/app/account-app/bitpay-payment-dialog.component.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919

2020
import { Component, Inject } from '@angular/core';
2121
import { MatLegacyDialogRef as MatDialogRef, MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA } from '@angular/material/legacy-dialog';
22+
import { ActivatedRoute, Router } from '@angular/router';
2223

2324
import { CartService } from './cart.service';
2425
import { RunboxWebmailAPI } from '../rmmapi/rbwebmail';
2526

27+
import { ProductOrder } from './product-order';
28+
import { Product } from './product';
29+
2630
export interface PaymentOption {
2731
id: string;
2832
displayName: string;
@@ -32,6 +36,10 @@ export interface PaymentOption {
3236
exchangeRate: string;
3337
}
3438

39+
class CartItem extends ProductOrder {
40+
product: Product;
41+
}
42+
3543
@Component({
3644
selector: 'app-bitpay-payment-dialog-component',
3745
templateUrl: './bitpay-payment-dialog.component.html',
@@ -59,6 +67,8 @@ export class BitpayPaymentDialogComponent {
5967
};
6068

6169
constructor(
70+
private route: ActivatedRoute,
71+
private router: Router,
6272
private cart: CartService,
6373
private rmmapi: RunboxWebmailAPI,
6474
public dialogRef: MatDialogRef<BitpayPaymentDialogComponent>,
@@ -103,4 +113,32 @@ export class BitpayPaymentDialogComponent {
103113
}
104114
this.dialogRef.close(false);
105115
}
116+
117+
domregHash: string;
118+
fromUrl = false;
119+
120+
121+
items: CartItem[] = [];
122+
123+
async initiateCryptoPayment(method: string) {
124+
const items = this.items.map(i => {
125+
return { pid: i.pid, apid: i.apid, quantity: i.quantity };
126+
});
127+
const currency = this.items[0].product.currency;
128+
this.rmmapi.orderProducts(items, method, currency, this.domregHash).subscribe(tx => {
129+
let dialogRef: MatDialogRef<any>;
130+
this.router.navigateByUrl('/account/receipt/' + tx.tid);
131+
if (!this.fromUrl) {
132+
this.cart.clear();
133+
}
134+
return;
135+
136+
dialogRef.afterClosed().subscribe(paid => {
137+
if (paid && !this.fromUrl) {
138+
this.cart.clear();
139+
}
140+
});
141+
});
142+
}
143+
106144
}

src/app/account-app/shopping-cart.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ <h4>
167167
</mat-expansion-panel-header>
168168
<p>
169169
<button id="payDirectly" mat-raised-button (click)="initiatePayment('giro')" color="primary">
170-
Bank Transfer or Cash Payment
170+
Cryptocurrency, Bank Transfer, or Cash Payment
171171
</button>
172172
</p>
173173
<p>

0 commit comments

Comments
 (0)