1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-08-26 23:09:46 +02:00

add credit via bitpay

This commit is contained in:
Kyle Spearrin 2019-02-21 22:48:59 -05:00
parent 7bcd0ac3e5
commit 2089237d23
3 changed files with 47 additions and 20 deletions

2
jslib

@ -1 +1 @@
Subproject commit 2b931963cd8dbebdcbdd6a418ac3ef72adb73539
Subproject commit 3362334d2ce2220fb0d1af322d88c9efec37763d

View File

@ -4,17 +4,16 @@
<div class="mb-4 text-lg" *ngIf="showOptions">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Method" id="credit-method-paypal"
[value]="paymentMethodType.PayPal" [(ngModel)]="method" (change)="changeMethod()">
[value]="paymentMethodType.PayPal" [(ngModel)]="method">
<label class="form-check-label" for="credit-method-paypal">
<i class="fa fa-fw fa-paypal"></i> PayPal</label>
</div>
<!--
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Method" id="credit-method-bitcoin" [value]="paymentMethodType.BitPay" [(ngModel)]="method" (change)="changeMethod()">
<input class="form-check-input" type="radio" name="Method" id="credit-method-bitcoin"
[value]="paymentMethodType.BitPay" [(ngModel)]="method">
<label class="form-check-label" for="credit-method-bitcoin">
<i class="fa fa-fw fa-bitcoin"></i> Bitcoin</label>
</div>
-->
</div>
<div class="form-group">
<div class="row">
@ -45,12 +44,12 @@
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="{{ppReturnUrl}}">
<input type="hidden" name="cancel_return" value="{{ppReturnUrl}}">
<input type="hidden" name="return" value="{{returnUrl}}">
<input type="hidden" name="cancel_return" value="{{returnUrl}}">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHosted">
<input type="hidden" name="amount" value="{{creditAmount}}">
<input type="hidden" name="custom" value="{{ppButtonCustomField}}">
<input type="hidden" name="item_name" value="Account Credit">
<input type="hidden" name="item_name" value="Bitwarden Account Credit">
<input type="hidden" name="item_number" value="{{subject}}">
</form>

View File

@ -11,12 +11,14 @@ import {
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { ApiService } from 'jslib/abstractions/api.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { UserService } from 'jslib/abstractions/user.service';
import { PaymentMethodType } from 'jslib/enums/paymentMethodType';
import { BitPayInvoiceRequest } from 'jslib/models/request/bitPayInvoiceRequest';
import { WebConstants } from '../../services/webConstants';
@Component({
@ -37,14 +39,18 @@ export class AddCreditComponent implements OnInit {
ppButtonFormAction = WebConstants.paypal.buttonActionProduction;
ppButtonBusinessId = WebConstants.paypal.businessIdProduction;
ppButtonCustomField: string;
ppReturnUrl: string;
ppLoading = false;
subject: string;
returnUrl: string;
formPromise: Promise<any>;
constructor(private userService: UserService, private i18nService: I18nService,
private userId: string;
private name: string;
private email: string;
constructor(private userService: UserService, private apiService: ApiService,
private analytics: Angulartics2, private toasterService: ToasterService,
platformUtilsService: PlatformUtilsService) {
private platformUtilsService: PlatformUtilsService) {
if (platformUtilsService.isDev()) {
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
@ -60,17 +66,19 @@ export class AddCreditComponent implements OnInit {
const org = await this.userService.getOrganization(this.organizationId);
if (org != null) {
this.subject = org.name;
this.name = org.name;
}
} else {
if (this.creditAmount == null) {
this.creditAmount = '10.00';
}
const userId = await this.userService.getUserId();
this.userId = await this.userService.getUserId();
this.subject = await this.userService.getEmail();
this.ppButtonCustomField = 'user_id:' + userId;
this.email = this.subject;
this.ppButtonCustomField = 'user_id:' + this.userId;
}
this.ppButtonCustomField += ',account_credit:1';
this.ppReturnUrl = window.location.href;
this.returnUrl = window.location.href;
}
async submit() {
@ -83,19 +91,30 @@ export class AddCreditComponent implements OnInit {
this.ppLoading = true;
return;
}
if (this.method === PaymentMethodType.BitPay) {
try {
const req = new BitPayInvoiceRequest();
req.email = this.email;
req.name = this.name;
req.credit = true;
req.amount = this.creditAmountNumber;
req.organizationId = this.organizationId;
req.userId = this.userId;
req.returnUrl = this.returnUrl;
this.formPromise = this.apiService.postBitPayInvoice(req);
const bitPayUrl: string = await this.formPromise;
this.platformUtilsService.launchUri(bitPayUrl);
} catch { }
return;
}
try {
this.analytics.eventTrack.next({
action: 'Added Credit',
});
this.toasterService.popAsync('success', null, this.i18nService.t('updatedPaymentMethod'));
this.onAdded.emit();
} catch { }
}
changeMethod() {
// TODO:
}
cancel() {
this.onCanceled.emit();
}
@ -113,4 +132,13 @@ export class AddCreditComponent implements OnInit {
} catch { }
this.creditAmount = '';
}
get creditAmountNumber(): number {
if (this.creditAmount != null && this.creditAmount !== '') {
try {
return parseFloat(this.creditAmount);
} catch { }
}
return null;
}
}