Skip to content

Commit

Permalink
Add demo with no shipping (in demo-angular).
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGardner committed May 9, 2020
1 parent 271bb60 commit 4cd5a32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion demo-angular/app/demo/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

<StackLayout class="page p-10">
<Label text="Standard Integration" class="h2"></Label>
<Button text="Demo" [nsRouterLink]="['/std']" class="btn btn-primary btn-active"></Button>
<Button text="Demo" [nsRouterLink]="['/std']" [queryParams]="{ shipping: 'true'}" class="btn btn-primary btn-active"></Button>
<Button text="Demo - No Shipping" [nsRouterLink]="['/std']" [queryParams]="{ shipping: 'false'}" class="btn btn-primary btn-active"></Button>

<StackLayout class="hr-light m-10"></StackLayout>
<Label text="Custom Integration" class="h2"></Label>
Expand Down
8 changes: 4 additions & 4 deletions demo-angular/app/demo/standard.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ActionBar title="Details" class="action-bar">
<ActionBar title="Standard Demo {{ requireShipping ? '' : '- No Shipping' }}" class="action-bar">
<NavigationButton text=""></NavigationButton>
</ActionBar>
<StackLayout class="page p-10">
Expand All @@ -20,8 +20,8 @@
</GridLayout>

<!-- Shipping methods -->
<StackLayout class="hr-light m-10"></StackLayout>
<GridLayout rows="auto" columns="auto,*" (tap)="showShipping()" class="list-group-item">
<StackLayout *ngIf="requireShipping" class="hr-light m-10"></StackLayout>
<GridLayout *ngIf="requireShipping" rows="auto" columns="auto,*" (tap)="showShipping()" class="list-group-item">
<Label row="0" col="0" text="Shipping Method"></Label>
<Label row="0" col="1" [text]="shippingType" class="text-right text-muted"></Label>
</GridLayout>
Expand All @@ -36,7 +36,7 @@
<StackLayout class="hr-light m-10"></StackLayout>
<Label [text]="errorMessage" class="text-danger" textWrap="true"></Label>
<Button text="Buy" [isEnabled]="canBuy" class="btn btn-primary btn-active" (tap)="buy()"></Button>

<ActivityIndicator [busy]="paymentInProgress" [visibility]="paymentInProgress ? 'visible' : 'collapse'"></ActivityIndicator>

<GridLayout>
Expand Down
13 changes: 9 additions & 4 deletions demo-angular/app/demo/standard.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeDetectorRef, Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { StripeAddress, StripePaymentData, StripePaymentListener, StripePaymentMethod, StripePaymentSession, StripeShippingMethod, StripeShippingMethods } from "nativescript-stripe/standard";
import { Page } from "tns-core-modules/ui/page";
import { Item } from "./item";
Expand All @@ -15,14 +16,18 @@ export class StandardComponent implements OnInit {
successMessage: string;
private paymentSession: StripePaymentSession;
paymentMethod: StripePaymentMethod;
requireShipping: boolean;
shippingInfo: StripeShippingMethod;
shippingAddress: StripeAddress;

constructor(
private page: Page,
private stripeService: StripeService,
route: ActivatedRoute,
public changeDetectionRef: ChangeDetectorRef
) { }
) {
this.requireShipping = route.snapshot.queryParamMap.get("shipping") === "true";
}

ngOnInit(): void {
this.item = {
Expand All @@ -31,7 +36,7 @@ export class StandardComponent implements OnInit {
price: 1200
};
this.paymentSession = this.stripeService.createPaymentSession(
this.page, this.item.price, new Listener(this)
this.page, this.item.price, this.requireShipping, new Listener(this)
);
}

Expand Down Expand Up @@ -72,10 +77,10 @@ export class StandardComponent implements OnInit {
if (this.paymentMethod) {
info += `Type= ${this.paymentMethod.type}; Brand= ${this.paymentMethod.brand}; ID= ${this.paymentMethod.stripeID}\n`;
}
if (this.shippingAddress) {
if (this.requireShipping && this.shippingAddress) {
const addr = this.shippingAddress;
info += [
`${this.shippingInfo.label} to:`,
this.shippingInfo ? `${this.shippingInfo.label} to:` : "No Shipping Info",
addr.name,
addr.line1,
addr.line2,
Expand Down
5 changes: 3 additions & 2 deletions demo-angular/app/demo/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class StripeService implements StripeBackendAPI {
StripeConfig.shared().publishableKey = publishableKey;
StripeConfig.shared().appleMerchantID = appleMerchantID;
StripeConfig.shared().companyName = "Demo Company";
StripeConfig.shared().requiredShippingAddressFields = [StripeShippingAddressField.PostalAddress];

this.customerSession = new StripeCustomerSession();
}
Expand Down Expand Up @@ -65,7 +64,9 @@ export class StripeService implements StripeBackendAPI {
return this._postRequest("confirm_payment_intent", content).then(response => response.content.toJSON());
}

createPaymentSession(page: Page, price: number, listener?: StripePaymentListener): StripePaymentSession {
createPaymentSession(page: Page, price: number, requireShipping: boolean, listener?: StripePaymentListener): StripePaymentSession {
StripeConfig.shared().requiredShippingAddressFields = requireShipping ?
[StripeShippingAddressField.PostalAddress] : [];
return new StripePaymentSession(page, this.customerSession, price, "usd", listener);
}

Expand Down

0 comments on commit 4cd5a32

Please sign in to comment.