Skip to content

Commit

Permalink
Merge pull request #3 from eddyinet/feature-apple-google-pay
Browse files Browse the repository at this point in the history
Support for Apple / Google Pay
  • Loading branch information
hansemannn committed Dec 18, 2023
2 parents c91bd48 + 5caf0dd commit 4c9ae2c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ Use the native Stripe SDK's (iOS/Android) in Titanium!

See the [app.js](./example/app.js) for a detailed example.

## Apple Pay Support
Follow steps listed here:

https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet#ios-card-scanning

- [x] Register for an Apple Merchant ID
- [x] Create a new Apple Pay certificate
- [x] Add Entitlements.plist to root with Merchant ID created above
- [x] Enable Apple Pay payment method in Stripe account:

https://dashboard.stripe.com/settings/payment_methods/connected_accounts

## Google Pay Support
Follow steps listed here:

https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=payment-sheet#android-google-pay

Join the Google Pay API Test group to use test cards in the Test Environment:

https://groups.google.com/g/googlepay-test-mode-stub-data/about

- [x] Enable Google Pay payment method in Stripe account:

https://dashboard.stripe.com/settings/payment_methods/connected_accounts


## Author

Hans Knöchel
Expand Down
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.0.0
version: 3.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: titanium-stripe
Expand Down
12 changes: 12 additions & 0 deletions android/src/ti/stripe/TiStripeHostActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,27 @@ class TiStripeHostActivity : ComponentActivity() {
val customerEphemeralKeySecret: String = params["customerEphemeralKeySecret"] as String
val paymentIntentClientSecret: String = params["paymentIntentClientSecret"] as String
val appearance: HashMap<*, *>? = params["appearance"] as? HashMap<*, *>
val merchantCountryCode: String = params["merchantCountryCode"] as String
val googlePayTest: Boolean? = params["googlePayTest"] as? Boolean

val customerConfig = PaymentSheet.CustomerConfiguration(
customerId,
customerEphemeralKeySecret
)

val googlePayConfiguration = PaymentSheet.GooglePayConfiguration(
environment = when (googlePayTest) {
true -> PaymentSheet.GooglePayConfiguration.Environment.Test
false -> PaymentSheet.GooglePayConfiguration.Environment.Production
null -> PaymentSheet.GooglePayConfiguration.Environment.Production
},
countryCode = merchantCountryCode
)

val configuration = PaymentSheet.Configuration.Builder(merchantDisplayName)
.customer(customerConfig)
.allowsDelayedPaymentMethods(true)
.googlePay(googlePayConfiguration)

appearance?.let {
configuration.appearance(mappedAppearance(it))
Expand Down
1 change: 1 addition & 0 deletions android/timodule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application>
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />
<activity android:name="ti.stripe.TiStripeHostActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:exported="true" android:label="Stripe" />
</application>
</manifest>
Expand Down
10 changes: 10 additions & 0 deletions example/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.in-app-payments</key>
<array>
<string>merchant.com.{{YOUR_APP_NAME}}</string>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function action() {
customerEphemeralKeySecret: credentials.ephemeralKey,
paymentIntentClientSecret: credentials.paymentIntent,
customerId: credentials.customer,
merchantId: credentials.merchantId, // For Apple Pay Support
merchantCountryCode: credentials.merchantCountryCode, // For Apple / Google Pay Support
googlePayTest:response['stripe_info']['googlePayTest'], // For Google Pay Support, set to True for test environment
// appearance: {
// font: {
// fontFamily: 'PT Mono',
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/TiStripeModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class TiStripeModule: TiModule {
let customerEphemeralKeySecret = params["customerEphemeralKeySecret"] as? String
let paymentIntentClientSecret = params["paymentIntentClientSecret"] as? String
let appearance = params["appearance"] as? [String: Any]
let merchantId = params["merchantId"] as? String
let merchantCountryCode = params["merchantCountryCode"] as? String

guard let customerId, let customerEphemeralKeySecret, let paymentIntentClientSecret, let callback else {
NSLog("[ERROR] Missing required parameters \"customerId\", \"customerEphemeralKeySecret\" and \"paymentIntentClientSecret\"")
Expand All @@ -56,6 +58,13 @@ class TiStripeModule: TiModule {
if let merchantDisplayName {
configuration.merchantDisplayName = merchantDisplayName
}

if let merchantId {
configuration.applePay = .init(
merchantId: merchantId,
merchantCountryCode: (merchantCountryCode ?? "US")
)
}

configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)

Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.0.0
version: 1.1.0
apiversion: 2
architectures: arm64 x86_64
description: titanium-stripe is a Swift based Titanium module.
Expand Down

0 comments on commit 4c9ae2c

Please sign in to comment.