@capgo/capacitor-pay 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapgoCapacitorPay'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ s.frameworks = 'PassKit'
18
+ end
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapgoCapacitorPay",
6
+ platforms: [.iOS(.v14)],
7
+ products: [
8
+ .library(
9
+ name: "CapgoCapacitorPay",
10
+ targets: ["PayPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "PayPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/PayPlugin"),
23
+ .testTarget(
24
+ name: "PayPluginTests",
25
+ dependencies: ["PayPlugin"],
26
+ path: "ios/Tests/PayPluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,350 @@
1
+ # @capgo/capacitor-pay
2
+ <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
3
+
4
+ <div align="center">
5
+ <h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo</a></h2>
6
+ <h2><a href="https://capgo.app/consulting/?ref=plugin"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
7
+ </div>
8
+
9
+ Capacitor plugin to trigger native payments with Apple Pay and Google Pay using a unified JavaScript API.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @capgo/capacitor-pay
15
+ npx cap sync
16
+ ```
17
+
18
+ ## Platform setup
19
+
20
+ Before invoking the plugin, complete the native configuration documented in this repository:
21
+
22
+ - **Apple Pay (iOS):** see [`docs/apple-pay-setup.md`](docs/apple-pay-setup.md) for merchant ID creation, certificates, Xcode entitlements, and device testing.
23
+ - **Google Pay (Android):** follow [`docs/google-pay-setup.md`](docs/google-pay-setup.md) to configure the business profile, tokenization settings, and runtime JSON payloads.
24
+
25
+ Finish both guides once per app to unlock the native payment sheets on devices.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { Pay } from '@capgo/capacitor-pay';
31
+
32
+ // Check availability on the current platform.
33
+ const availability = await Pay.isPayAvailable({
34
+ apple: {
35
+ supportedNetworks: ['visa', 'masterCard', 'amex'],
36
+ },
37
+ google: {
38
+ // Optional: falls back to a basic CARD request if omitted.
39
+ isReadyToPayRequest: {
40
+ allowedPaymentMethods: [
41
+ {
42
+ type: 'CARD',
43
+ parameters: {
44
+ allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
45
+ allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
46
+ },
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ });
52
+
53
+ if (!availability.available) {
54
+ // Surface a friendly message or provide an alternative checkout.
55
+ return;
56
+ }
57
+
58
+ if (availability.platform === 'ios') {
59
+ const result = await Pay.requestPayment({
60
+ apple: {
61
+ merchantIdentifier: 'merchant.com.example.app',
62
+ countryCode: 'US',
63
+ currencyCode: 'USD',
64
+ supportedNetworks: ['visa', 'masterCard'],
65
+ paymentSummaryItems: [
66
+ { label: 'Example Product', amount: '19.99' },
67
+ { label: 'Tax', amount: '1.60' },
68
+ { label: 'Example Store', amount: '21.59' },
69
+ ],
70
+ requiredShippingContactFields: ['postalAddress', 'name', 'emailAddress'],
71
+ },
72
+ });
73
+ console.log(result.apple?.paymentData);
74
+ } else if (availability.platform === 'android') {
75
+ const result = await Pay.requestPayment({
76
+ google: {
77
+ environment: 'test',
78
+ paymentDataRequest: {
79
+ apiVersion: 2,
80
+ apiVersionMinor: 0,
81
+ allowedPaymentMethods: [
82
+ {
83
+ type: 'CARD',
84
+ parameters: {
85
+ allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
86
+ allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
87
+ billingAddressRequired: true,
88
+ billingAddressParameters: {
89
+ format: 'FULL',
90
+ },
91
+ },
92
+ tokenizationSpecification: {
93
+ type: 'PAYMENT_GATEWAY',
94
+ parameters: {
95
+ gateway: 'example',
96
+ gatewayMerchantId: 'exampleGatewayMerchantId',
97
+ },
98
+ },
99
+ },
100
+ ],
101
+ merchantInfo: {
102
+ merchantId: '01234567890123456789',
103
+ merchantName: 'Example Merchant',
104
+ },
105
+ transactionInfo: {
106
+ totalPriceStatus: 'FINAL',
107
+ totalPrice: '21.59',
108
+ currencyCode: 'USD',
109
+ countryCode: 'US',
110
+ },
111
+ },
112
+ },
113
+ });
114
+ console.log(result.google?.paymentData);
115
+ }
116
+ ```
117
+
118
+ ## API
119
+
120
+ <docgen-index>
121
+
122
+ * [`isPayAvailable(...)`](#ispayavailable)
123
+ * [`requestPayment(...)`](#requestpayment)
124
+ * [Interfaces](#interfaces)
125
+ * [Type Aliases](#type-aliases)
126
+
127
+ </docgen-index>
128
+
129
+ <docgen-api>
130
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
131
+
132
+ ### isPayAvailable(...)
133
+
134
+ ```typescript
135
+ isPayAvailable(options?: PayAvailabilityOptions | undefined) => Promise<PayAvailabilityResult>
136
+ ```
137
+
138
+ Checks whether native pay is available on the current platform.
139
+ On iOS this evaluates Apple Pay, on Android it evaluates Google Pay.
140
+
141
+ | Param | Type |
142
+ | ------------- | ------------------------------------------------------------------------- |
143
+ | **`options`** | <code><a href="#payavailabilityoptions">PayAvailabilityOptions</a></code> |
144
+
145
+ **Returns:** <code>Promise&lt;<a href="#payavailabilityresult">PayAvailabilityResult</a>&gt;</code>
146
+
147
+ --------------------
148
+
149
+
150
+ ### requestPayment(...)
151
+
152
+ ```typescript
153
+ requestPayment(options: PayPaymentOptions) => Promise<PayPaymentResult>
154
+ ```
155
+
156
+ Presents the native pay sheet for the current platform.
157
+ Provide the Apple Pay configuration on iOS and the Google Pay configuration on Android.
158
+
159
+ | Param | Type |
160
+ | ------------- | --------------------------------------------------------------- |
161
+ | **`options`** | <code><a href="#paypaymentoptions">PayPaymentOptions</a></code> |
162
+
163
+ **Returns:** <code>Promise&lt;<a href="#paypaymentresult">PayPaymentResult</a>&gt;</code>
164
+
165
+ --------------------
166
+
167
+
168
+ ### Interfaces
169
+
170
+
171
+ #### PayAvailabilityResult
172
+
173
+ | Prop | Type |
174
+ | --------------- | ----------------------------------------------------------------------------------- |
175
+ | **`available`** | <code>boolean</code> |
176
+ | **`platform`** | <code><a href="#payplatform">PayPlatform</a></code> |
177
+ | **`apple`** | <code><a href="#applepayavailabilityresult">ApplePayAvailabilityResult</a></code> |
178
+ | **`google`** | <code><a href="#googlepayavailabilityresult">GooglePayAvailabilityResult</a></code> |
179
+
180
+
181
+ #### ApplePayAvailabilityResult
182
+
183
+ | Prop | Type | Description |
184
+ | ---------------------------------- | -------------------- | ------------------------------------------------------------------------------------ |
185
+ | **`canMakePayments`** | <code>boolean</code> | Indicates whether the device can make Apple Pay payments in general. |
186
+ | **`canMakePaymentsUsingNetworks`** | <code>boolean</code> | Indicates whether the device can make Apple Pay payments with the supplied networks. |
187
+
188
+
189
+ #### GooglePayAvailabilityResult
190
+
191
+ | Prop | Type | Description |
192
+ | ------------- | -------------------- | ------------------------------------------------------------------------------ |
193
+ | **`isReady`** | <code>boolean</code> | Indicates whether the Google Pay API is available for the supplied parameters. |
194
+
195
+
196
+ #### PayAvailabilityOptions
197
+
198
+ | Prop | Type |
199
+ | ------------ | ------------------------------------------------------------------------------------- |
200
+ | **`apple`** | <code><a href="#applepayavailabilityoptions">ApplePayAvailabilityOptions</a></code> |
201
+ | **`google`** | <code><a href="#googlepayavailabilityoptions">GooglePayAvailabilityOptions</a></code> |
202
+
203
+
204
+ #### ApplePayAvailabilityOptions
205
+
206
+ | Prop | Type | Description |
207
+ | ----------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
208
+ | **`supportedNetworks`** | <code>ApplePayNetwork[]</code> | Optional list of payment networks you intend to use. Passing networks determines the return value of `canMakePaymentsUsingNetworks`. |
209
+
210
+
211
+ #### GooglePayAvailabilityOptions
212
+
213
+ | Prop | Type | Description |
214
+ | ------------------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
215
+ | **`environment`** | <code><a href="#googlepayenvironment">GooglePayEnvironment</a></code> | Environment used to construct the Google Payments client. Defaults to `'test'`. |
216
+ | **`isReadyToPayRequest`** | <code><a href="#record">Record</a>&lt;string, unknown&gt;</code> | Raw `IsReadyToPayRequest` JSON as defined by the Google Pay API. Supply the card networks and auth methods you intend to support at runtime. |
217
+
218
+
219
+ #### PayPaymentResult
220
+
221
+ | Prop | Type |
222
+ | -------------- | ------------------------------------------------------------------------------------------------ |
223
+ | **`platform`** | <code><a href="#exclude">Exclude</a>&lt;<a href="#payplatform">PayPlatform</a>, 'web'&gt;</code> |
224
+ | **`apple`** | <code><a href="#applepaypaymentresult">ApplePayPaymentResult</a></code> |
225
+ | **`google`** | <code><a href="#googlepaypaymentresult">GooglePayPaymentResult</a></code> |
226
+
227
+
228
+ #### ApplePayPaymentResult
229
+
230
+ | Prop | Type | Description |
231
+ | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
232
+ | **`paymentData`** | <code>string</code> | Raw payment token encoded as base64 string. |
233
+ | **`paymentString`** | <code>string</code> | Raw payment token JSON string, useful for debugging. |
234
+ | **`transactionIdentifier`** | <code>string</code> | Payment transaction identifier. |
235
+ | **`paymentMethod`** | <code>{ displayName?: string; network?: <a href="#applepaynetwork">ApplePayNetwork</a>; type: 'credit' \| 'debit' \| 'prepaid' \| 'store'; }</code> | |
236
+ | **`shippingContact`** | <code><a href="#applepaycontact">ApplePayContact</a></code> | |
237
+ | **`billingContact`** | <code><a href="#applepaycontact">ApplePayContact</a></code> | |
238
+
239
+
240
+ #### ApplePayContact
241
+
242
+ | Prop | Type |
243
+ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
244
+ | **`name`** | <code>{ givenName?: string; familyName?: string; middleName?: string; namePrefix?: string; nameSuffix?: string; nickname?: string; }</code> |
245
+ | **`emailAddress`** | <code>string</code> |
246
+ | **`phoneNumber`** | <code>string</code> |
247
+ | **`postalAddress`** | <code>{ street?: string; city?: string; state?: string; postalCode?: string; country?: string; isoCountryCode?: string; subAdministrativeArea?: string; subLocality?: string; }</code> |
248
+
249
+
250
+ #### GooglePayPaymentResult
251
+
252
+ | Prop | Type | Description |
253
+ | ----------------- | ---------------------------------------------------------------- | ------------------------------------ |
254
+ | **`paymentData`** | <code><a href="#record">Record</a>&lt;string, unknown&gt;</code> | Payment data returned by Google Pay. |
255
+
256
+
257
+ #### PayPaymentOptions
258
+
259
+ | Prop | Type |
260
+ | ------------ | --------------------------------------------------------------------------- |
261
+ | **`apple`** | <code><a href="#applepaypaymentoptions">ApplePayPaymentOptions</a></code> |
262
+ | **`google`** | <code><a href="#googlepaypaymentoptions">GooglePayPaymentOptions</a></code> |
263
+
264
+
265
+ #### ApplePayPaymentOptions
266
+
267
+ | Prop | Type | Description |
268
+ | ----------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------ |
269
+ | **`merchantIdentifier`** | <code>string</code> | Merchant identifier created in the Apple Developer portal. |
270
+ | **`countryCode`** | <code>string</code> | Two-letter ISO 3166 country code. |
271
+ | **`currencyCode`** | <code>string</code> | Three-letter ISO 4217 currency code. |
272
+ | **`paymentSummaryItems`** | <code>ApplePaySummaryItem[]</code> | Payment summary items displayed in the Apple Pay sheet. |
273
+ | **`supportedNetworks`** | <code>ApplePayNetwork[]</code> | Card networks to support. |
274
+ | **`merchantCapabilities`** | <code>ApplePayMerchantCapability[]</code> | Merchant payment capabilities. Defaults to ['3DS'] when omitted. |
275
+ | **`requiredShippingContactFields`** | <code>ApplePayContactField[]</code> | Contact fields that must be supplied for shipping. |
276
+ | **`requiredBillingContactFields`** | <code>ApplePayContactField[]</code> | Contact fields that must be supplied for billing. |
277
+ | **`shippingType`** | <code><a href="#applepayshippingtype">ApplePayShippingType</a></code> | Controls the shipping flow presented to the user. |
278
+ | **`supportedCountries`** | <code>string[]</code> | Optional ISO 3166 country codes where the merchant is supported. |
279
+ | **`applicationData`** | <code>string</code> | Optional opaque application data passed back in the payment token. |
280
+
281
+
282
+ #### ApplePaySummaryItem
283
+
284
+ | Prop | Type |
285
+ | ------------ | --------------------------------------------------------------------------- |
286
+ | **`label`** | <code>string</code> |
287
+ | **`amount`** | <code>string</code> |
288
+ | **`type`** | <code><a href="#applepaysummaryitemtype">ApplePaySummaryItemType</a></code> |
289
+
290
+
291
+ #### GooglePayPaymentOptions
292
+
293
+ | Prop | Type | Description |
294
+ | ------------------------ | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
295
+ | **`environment`** | <code><a href="#googlepayenvironment">GooglePayEnvironment</a></code> | Environment used to construct the Google Payments client. Defaults to `'test'`. |
296
+ | **`paymentDataRequest`** | <code><a href="#record">Record</a>&lt;string, unknown&gt;</code> | Raw `PaymentDataRequest` JSON as defined by the Google Pay API. Provide transaction details, merchant info, and tokenization parameters. |
297
+
298
+
299
+ ### Type Aliases
300
+
301
+
302
+ #### PayPlatform
303
+
304
+ <code>'ios' | 'android' | 'web'</code>
305
+
306
+
307
+ #### ApplePayNetwork
308
+
309
+ <code>'amex' | 'chinaUnionPay' | 'discover' | 'eftpos' | 'electron' | 'girocard' | 'interac' | 'jcb' | 'mada' | 'maestro' | 'masterCard' | 'privateLabel' | 'quicPay' | 'suica' | 'visa' | 'vPay' | 'id' | 'cartesBancaires'</code>
310
+
311
+
312
+ #### GooglePayEnvironment
313
+
314
+ <code>'test' | 'production'</code>
315
+
316
+
317
+ #### Record
318
+
319
+ Construct a type with a set of properties K of type T
320
+
321
+ <code>{
322
  [P in K]: T;
1
323
  }</code>
324
+
325
+
326
+ #### Exclude
327
+
328
+ <a href="#exclude">Exclude</a> from T those types that are assignable to U
329
+
330
+ <code>T extends U ? never : T</code>
331
+
332
+
333
+ #### ApplePaySummaryItemType
334
+
335
+ <code>'final' | 'pending'</code>
336
+
337
+
338
+ #### ApplePayMerchantCapability
339
+
340
+ <code>'3DS' | 'credit' | 'debit' | 'emv'</code>
341
+
342
+
343
+ #### ApplePayContactField
344
+
345
+ <code>'emailAddress' | 'name' | 'phoneNumber' | 'postalAddress'</code>
346
+
347
+
348
+ #### ApplePayShippingType
349
+
350
+ <code>'shipping' | 'delivery' | 'servicePickup' | 'storePickup'</code>
351
+
352
+ </docgen-api>
@@ -0,0 +1,59 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.7.2'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "app.capgo.pay"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ implementation "com.google.android.gms:play-services-wallet:19.2.0"
56
+ testImplementation "junit:junit:$junitVersion"
57
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
58
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
59
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>