mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-30 13:03:53 +01:00
add credit via bitpay
This commit is contained in:
parent
7bcd0ac3e5
commit
2089237d23
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit 2b931963cd8dbebdcbdd6a418ac3ef72adb73539
|
Subproject commit 3362334d2ce2220fb0d1af322d88c9efec37763d
|
@ -4,17 +4,16 @@
|
|||||||
<div class="mb-4 text-lg" *ngIf="showOptions">
|
<div class="mb-4 text-lg" *ngIf="showOptions">
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="radio" name="Method" id="credit-method-paypal"
|
<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">
|
<label class="form-check-label" for="credit-method-paypal">
|
||||||
<i class="fa fa-fw fa-paypal"></i> PayPal</label>
|
<i class="fa fa-fw fa-paypal"></i> PayPal</label>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
|
||||||
<div class="form-check form-check-inline">
|
<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">
|
<label class="form-check-label" for="credit-method-bitcoin">
|
||||||
<i class="fa fa-fw fa-bitcoin"></i> Bitcoin</label>
|
<i class="fa fa-fw fa-bitcoin"></i> Bitcoin</label>
|
||||||
</div>
|
</div>
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -45,12 +44,12 @@
|
|||||||
<input type="hidden" name="no_note" value="1">
|
<input type="hidden" name="no_note" value="1">
|
||||||
<input type="hidden" name="no_shipping" value="1">
|
<input type="hidden" name="no_shipping" value="1">
|
||||||
<input type="hidden" name="rm" value="1">
|
<input type="hidden" name="rm" value="1">
|
||||||
<input type="hidden" name="return" value="{{ppReturnUrl}}">
|
<input type="hidden" name="return" value="{{returnUrl}}">
|
||||||
<input type="hidden" name="cancel_return" value="{{ppReturnUrl}}">
|
<input type="hidden" name="cancel_return" value="{{returnUrl}}">
|
||||||
<input type="hidden" name="currency_code" value="USD">
|
<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="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHosted">
|
||||||
<input type="hidden" name="amount" value="{{creditAmount}}">
|
<input type="hidden" name="amount" value="{{creditAmount}}">
|
||||||
<input type="hidden" name="custom" value="{{ppButtonCustomField}}">
|
<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}}">
|
<input type="hidden" name="item_number" value="{{subject}}">
|
||||||
</form>
|
</form>
|
||||||
|
@ -11,12 +11,14 @@ import {
|
|||||||
import { ToasterService } from 'angular2-toaster';
|
import { ToasterService } from 'angular2-toaster';
|
||||||
import { Angulartics2 } from 'angulartics2';
|
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 { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
import { UserService } from 'jslib/abstractions/user.service';
|
import { UserService } from 'jslib/abstractions/user.service';
|
||||||
|
|
||||||
import { PaymentMethodType } from 'jslib/enums/paymentMethodType';
|
import { PaymentMethodType } from 'jslib/enums/paymentMethodType';
|
||||||
|
|
||||||
|
import { BitPayInvoiceRequest } from 'jslib/models/request/bitPayInvoiceRequest';
|
||||||
|
|
||||||
import { WebConstants } from '../../services/webConstants';
|
import { WebConstants } from '../../services/webConstants';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -37,14 +39,18 @@ export class AddCreditComponent implements OnInit {
|
|||||||
ppButtonFormAction = WebConstants.paypal.buttonActionProduction;
|
ppButtonFormAction = WebConstants.paypal.buttonActionProduction;
|
||||||
ppButtonBusinessId = WebConstants.paypal.businessIdProduction;
|
ppButtonBusinessId = WebConstants.paypal.businessIdProduction;
|
||||||
ppButtonCustomField: string;
|
ppButtonCustomField: string;
|
||||||
ppReturnUrl: string;
|
|
||||||
ppLoading = false;
|
ppLoading = false;
|
||||||
subject: string;
|
subject: string;
|
||||||
|
returnUrl: string;
|
||||||
formPromise: Promise<any>;
|
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,
|
private analytics: Angulartics2, private toasterService: ToasterService,
|
||||||
platformUtilsService: PlatformUtilsService) {
|
private platformUtilsService: PlatformUtilsService) {
|
||||||
if (platformUtilsService.isDev()) {
|
if (platformUtilsService.isDev()) {
|
||||||
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
|
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
|
||||||
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
|
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
|
||||||
@ -60,17 +66,19 @@ export class AddCreditComponent implements OnInit {
|
|||||||
const org = await this.userService.getOrganization(this.organizationId);
|
const org = await this.userService.getOrganization(this.organizationId);
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
this.subject = org.name;
|
this.subject = org.name;
|
||||||
|
this.name = org.name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.creditAmount == null) {
|
if (this.creditAmount == null) {
|
||||||
this.creditAmount = '10.00';
|
this.creditAmount = '10.00';
|
||||||
}
|
}
|
||||||
const userId = await this.userService.getUserId();
|
this.userId = await this.userService.getUserId();
|
||||||
this.subject = await this.userService.getEmail();
|
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.ppButtonCustomField += ',account_credit:1';
|
||||||
this.ppReturnUrl = window.location.href;
|
this.returnUrl = window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
async submit() {
|
async submit() {
|
||||||
@ -83,19 +91,30 @@ export class AddCreditComponent implements OnInit {
|
|||||||
this.ppLoading = true;
|
this.ppLoading = true;
|
||||||
return;
|
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 {
|
try {
|
||||||
this.analytics.eventTrack.next({
|
this.analytics.eventTrack.next({
|
||||||
action: 'Added Credit',
|
action: 'Added Credit',
|
||||||
});
|
});
|
||||||
this.toasterService.popAsync('success', null, this.i18nService.t('updatedPaymentMethod'));
|
|
||||||
this.onAdded.emit();
|
this.onAdded.emit();
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
changeMethod() {
|
|
||||||
// TODO:
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
this.onCanceled.emit();
|
this.onCanceled.emit();
|
||||||
}
|
}
|
||||||
@ -113,4 +132,13 @@ export class AddCreditComponent implements OnInit {
|
|||||||
} catch { }
|
} catch { }
|
||||||
this.creditAmount = '';
|
this.creditAmount = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get creditAmountNumber(): number {
|
||||||
|
if (this.creditAmount != null && this.creditAmount !== '') {
|
||||||
|
try {
|
||||||
|
return parseFloat(this.creditAmount);
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user