Skip to content

Commit

Permalink
Merge pull request #344 from capacitor-community/feat/rename_collect
Browse files Browse the repository at this point in the history
feat(terminal): rename collect to collectPaymentMethod
  • Loading branch information
rdlabo authored Mar 25, 2024
2 parents 0fab4fc + a3e3431 commit 3278810
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 87 deletions.
14 changes: 6 additions & 8 deletions demo/angular/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:minSdkVersion="31" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" android:minSdkVersion="31" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -62,12 +68,4 @@
<!-- android:name="com.getcapacitor.community.stripe.stripe_account"-->
<!-- android:value="@string/stripe_account"/>-->
</application>

<!-- Permissions -->

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
</manifest>
2 changes: 1 addition & 1 deletion demo/angular/android/variables.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
minSdkVersion = 26
compileSdkVersion = 34
targetSdkVersion = 33
targetSdkVersion = 34
androidxActivityVersion = '1.7.0'
androidxAppCompatVersion = '1.6.1'
androidxCoordinatorLayoutVersion = '1.2.0'
Expand Down
18 changes: 9 additions & 9 deletions demo/angular/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PODS:
- Capacitor (5.0.0):
- CapacitorCordova
- CapacitorCommunityStripe (5.4.4):
- CapacitorCommunityStripe (5.4.6):
- Capacitor
- StripeApplePay (~> 23.24.0)
- StripePaymentSheet (~> 23.24.0)
- CapacitorCommunityStripeIdentity (5.4.4):
- CapacitorCommunityStripeIdentity (5.4.6):
- Capacitor
- StripeIdentity (~> 23.24.0)
- CapacitorCommunityStripeTerminal (5.4.4):
- CapacitorCommunityStripeTerminal (5.5.0-beta.1):
- Capacitor
- StripeTerminal (~> 3.3.1)
- StripeTerminal (~> 3.4.0)
- CapacitorCordova (5.0.0)
- StripeApplePay (23.24.1):
- StripeCore (= 23.24.1)
Expand All @@ -35,7 +35,7 @@ PODS:
- StripeCore (= 23.24.1)
- StripePayments (= 23.24.1)
- StripeUICore (= 23.24.1)
- StripeTerminal (3.3.1)
- StripeTerminal (3.4.0)
- StripeUICore (23.24.1):
- StripeCore (= 23.24.1)

Expand Down Expand Up @@ -72,9 +72,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Capacitor: b332cb737d447561e854039fb72195206685dce2
CapacitorCommunityStripe: 5729a153eb5cb6ac28dab496afff3416471983b0
CapacitorCommunityStripeIdentity: 4dd105cfb8ef4b091d687fb05d88f60371bba4ce
CapacitorCommunityStripeTerminal: e7e725b9bbefed0500503105f930fd90394b6bd8
CapacitorCommunityStripe: 3fee1254742ce744f6576bda1fc899cfa053e797
CapacitorCommunityStripeIdentity: 3996571069f39e5c9820f15598e3ccf9c507f9a7
CapacitorCommunityStripeTerminal: add001625e3eee13be86a241fd59d56b4f0fa083
CapacitorCordova: 4ea17670ee562680988a7ce9db68dee5160fe564
StripeApplePay: ffc296e6eba1d9ce86e4b5c4733540bce6f1b3eb
StripeCameraCore: 3459f80598a8cd2060ba3e28e647ea50a94912cd
Expand All @@ -83,7 +83,7 @@ SPEC CHECKSUMS:
StripePayments: 4fdc6b22595887753851aee425dc9aafad39e8ef
StripePaymentSheet: 9f433a11fa6578939c555b6a56c87b7a958845d6
StripePaymentsUI: 42a4c50bd30a19c102685eeb7269a52c71a79bb3
StripeTerminal: 369ef0cf0b90d838f42be1a0b371475986f4b79f
StripeTerminal: bdca32b058179ff3595c7d886a1cc45d4e810c5c
StripeUICore: 510afeb8f0cb8ba5f99563a23c5ad6cc7f58a007

PODFILE CHECKSUM: 2430ef1d0136ea2c0f7e2696daff19ed8cd27595
Expand Down
109 changes: 95 additions & 14 deletions demo/angular/src/app/terminal/terminal.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';

import { FormsModule } from '@angular/forms';
import {
AlertController,
IonContent,
IonHeader,
IonIcon,
Expand All @@ -17,6 +18,7 @@ import {
import { HttpClient } from '@angular/common/http';
import { HelperService } from '../shared/helper.service';
import {
ReaderInterface,
StripeTerminal,
TerminalConnectTypes,
TerminalEventsEnum,
Expand Down Expand Up @@ -63,7 +65,7 @@ const happyPathItems: ITestItems[] = [
},
{
type: 'method',
name: 'collect',
name: 'collectPaymentMethod',
},
{
type: 'event',
Expand Down Expand Up @@ -110,11 +112,11 @@ const cancelPathItems: ITestItems[] = [
},
{
type: 'method',
name: 'collect',
name: 'collectPaymentMethod',
},
{
type: 'method',
name: 'cancelCollect',
name: 'cancelCollectPaymentMethod',
},
{
type: 'event',
Expand Down Expand Up @@ -184,8 +186,11 @@ export class TerminalPage {
public eventItems: ITestItems[] = [];
public terminalConnectTypes = TerminalConnectTypes;
private readonly listenerHandlers: PluginListenerHandle[] = [];

public readonly platform = inject(Platform);
private readonly alertCtrl = inject(AlertController);

constructor(
public platform: Platform,
private http: HttpClient,
private helper: HelperService,
) {
Expand Down Expand Up @@ -243,7 +248,13 @@ export class TerminalPage {

const result = await StripeTerminal.discoverReaders({
type: readerType,
locationId: 'tml_FOUOdQVIxvVdvN',
locationId:
this.platform.is('android') &&
[TerminalConnectTypes.Bluetooth, TerminalConnectTypes.Usb].includes(
readerType,
)
? 'tml_Ff37mAmk1XdBYT'
: 'tml_FOUOdQVIxvVdvN',
}).catch((e) => {
this.helper.updateItem(this.eventItems, 'discoverReaders', false);
throw e;
Expand All @@ -255,9 +266,22 @@ export class TerminalPage {
result.readers.length > 0,
);

console.log(result);

const selectedReader =
result.readers.length === 1
? result.readers[0]
: await this.alertFilterReaders(result.readers);
console.log(selectedReader);
if (!selectedReader) {
alert('No reader selected');
return;
}

await StripeTerminal.connectReader({
reader: result.readers[0],
reader: selectedReader,
}).catch((e) => {
alert(e);
this.helper.updateItem(this.eventItems, 'connectReader', false);
throw e;
});
Expand All @@ -281,20 +305,34 @@ export class TerminalPage {
true,
);

await StripeTerminal.collect({ paymentIntent })
.then(() => this.helper.updateItem(this.eventItems, 'collect', true))
await StripeTerminal.collectPaymentMethod({ paymentIntent })
.then(() =>
this.helper.updateItem(this.eventItems, 'collectPaymentMethod', true),
)
.catch(async (e) => {
await this.helper.updateItem(this.eventItems, 'collect', false);
await this.helper.updateItem(
this.eventItems,
'collectPaymentMethod',
false,
);
throw e;
});

if (type === 'cancelPath') {
await new Promise((resolve) => setTimeout(resolve, 2000));
await StripeTerminal.cancelCollect().catch(async (e) => {
await this.helper.updateItem(this.eventItems, 'cancelCollect', false);
await StripeTerminal.cancelCollectPaymentMethod().catch(async (e) => {
await this.helper.updateItem(
this.eventItems,
'cancelCollectPaymentMethod',
false,
);
throw e;
});
await this.helper.updateItem(this.eventItems, 'cancelCollect', true);
await this.helper.updateItem(
this.eventItems,
'cancelCollectPaymentMethod',
true,
);
} else {
await StripeTerminal.confirmPaymentIntent();
await this.helper.updateItem(
Expand All @@ -304,6 +342,7 @@ export class TerminalPage {
);
}

await StripeTerminal.disconnectReader();
this.listenerHandlers.forEach((handler) => handler.remove());
}

Expand Down Expand Up @@ -363,9 +402,19 @@ export class TerminalPage {
result.readers.length > 0,
);

const selectedReader =
result.readers.length === 1
? result.readers[0]
: await this.alertFilterReaders(result.readers);
if (!selectedReader) {
alert('No reader selected');
return;
}

await StripeTerminal.connectReader({
reader: result.readers[0],
reader: selectedReader,
}).catch((e) => {
alert(e);
this.helper.updateItem(this.eventItems, 'connectReader', false);
throw e;
});
Expand All @@ -389,4 +438,36 @@ export class TerminalPage {

this.listenerHandlers.forEach((handler) => handler.remove());
}

private alertFilterReaders(
readers: ReaderInterface[],
): Promise<ReaderInterface | undefined> {
return new Promise(async (resolve) => {
const alert = await this.alertCtrl.create({
header: `Select a reader`,
message: `Select a reader to connect to.`,
inputs: readers.map((reader, index) => ({
name: 'serialNumber',
type: 'radio',
label: reader.serialNumber,
value: reader.serialNumber,
checked: index === 0,
})),
buttons: [
{
text: `Cancel`,
role: 'cancel',
handler: () => resolve(undefined),
},
{
text: `Submit`,
handler: (d) => {
resolve(readers.find((reader) => reader.serialNumber === d));
},
},
],
});
await alert.present();
});
}
}
9 changes: 0 additions & 9 deletions demo/angular/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,3 @@ export const environment = {
// api: 'http://localhost:3000/',
api: 'https://j3x0ln9gj7.execute-api.ap-northeast-1.amazonaws.com/dev/',
};

/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
2 changes: 1 addition & 1 deletion packages/terminal/CapacitorCommunityStripeTerminal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Pod::Spec.new do |s|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.dependency 'StripeTerminal', '~> 3.3.1'
s.dependency 'StripeTerminal', '~> 3.4.0'
s.swift_version = '5.1'
end
Loading

0 comments on commit 3278810

Please sign in to comment.