Skip to content

Commit

Permalink
Add Apple Pay, improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
bndkt committed Jun 11, 2024
1 parent 40b5318 commit 4b56a95
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ In your app’s Expo config (app.json, or app.config.js), make sure that react-n
- **requestEphemeralUserNotification** (boolean): Enables notifications for the App Clip (see [Apple Developer Docs](https://developer.apple.com/documentation/app_clips/enabling_notifications_in_app_clips))
- **requestLocationConfirmation** (boolean): Allow App Clip access to location data (see [Apple Developer Docs](https://developer.apple.com/documentation/app_clips/confirming_the_user_s_physical_location))
- **appleSignin** (boolean): Enable "Sign in with Apple" for the App Clip
- **applePayMerchantIds** (string[]): Enable Apple Pay capability with provided merchant IDs.
- **excludedPackages** (string[]): Packages to exclude from autolinking for the App Clip to reduce bundle size (see below).

## Native capabilities
Expand Down
14 changes: 13 additions & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@
"favicon": "./assets/favicon.png"
},
"plugins": [
"../app.plugin.js",
[
"../app.plugin.js",
{
"name": "Example Clip",
"groupIdentifier": "dev.example.app",
"deploymentTarget": "14.2",
"requestEphemeralUserNotification": true,
"requestLocationConfirmation": true,
"appleSignin": true,
"applePayMerchantIds": ["dev.example.app"],
"excludedPackages": ["@shopify/react-native-skia"]
}
],
[
"expo-build-properties",
{
Expand Down
12 changes: 10 additions & 2 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const withAppClip: ConfigPlugin<{
requestEphemeralUserNotification?: boolean;
requestLocationConfirmation?: boolean;
appleSignin?: boolean;
applePayMerchantIds?: string[];
excludedPackages?: string[];
}> = (
config,
Expand All @@ -23,6 +24,7 @@ const withAppClip: ConfigPlugin<{
requestEphemeralUserNotification,
requestLocationConfirmation,
appleSignin,
applePayMerchantIds,
excludedPackages,
} = {},
) => {
Expand All @@ -38,8 +40,14 @@ const withAppClip: ConfigPlugin<{
const targetName = `${IOSConfig.XcodeUtils.sanitizedName(config.name)}Clip`;

const modifiedConfig = withPlugins(config, [
[withConfig, { targetName, bundleIdentifier }],
[withEntitlements, { targetName, groupIdentifier, appleSignin }],
[
withConfig,
{ targetName, bundleIdentifier, appleSignin, applePayMerchantIds },
],
[
withEntitlements,
{ targetName, groupIdentifier, appleSignin, applePayMerchantIds },
],
[withPodfile, { targetName, excludedPackages }],
[
withPlist,
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/lib/getAppClipEntitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export function getAppClipEntitlements(
{
groupIdentifier,
appleSignin,
applePayMerchantIds,
}: {
groupIdentifier?: string;
appleSignin: boolean;
applePayMerchantIds?: string[];
},
) {
const appBundleIdentifier = iosConfig?.bundleIdentifier;
Expand All @@ -25,6 +27,10 @@ export function getAppClipEntitlements(
entitlements["com.apple.developer.applesignin"] = ["Default"];
}

if (applePayMerchantIds) {
entitlements["com.apple.developer.in-app-payments"] = applePayMerchantIds;
}

if (iosConfig?.associatedDomains) {
entitlements["com.apple.developer.associated-domains"] =
iosConfig.associatedDomains;
Expand Down
17 changes: 12 additions & 5 deletions plugin/src/withConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { ConfigPlugin } from "expo/config-plugins";
import { getAppClipEntitlements } from "./lib/getAppClipEntitlements";

export const withConfig: ConfigPlugin<{
targetName: string;
bundleIdentifier: string;
}> = (config, { targetName, bundleIdentifier }) => {
appleSignin: boolean;
applePayMerchantIds: string[];
}> = (
config,
{ targetName, bundleIdentifier, appleSignin, applePayMerchantIds },
) => {
let configIndex: null | number = null;
config.extra?.eas?.build?.experimental?.ios?.appExtensions?.forEach(
(ext: { targetName: string }, index: number) => {
Expand Down Expand Up @@ -46,10 +52,11 @@ export const withConfig: ConfigPlugin<{

appClipConfig.entitlements = {
...appClipConfig.entitlements,
// ...getAppClipEntitlements(config.ios, {
// appleSignin,
// // groupIdentifier, // Throws an error in EAS
// }),
...getAppClipEntitlements(config.ios, {
appleSignin,
applePayMerchantIds,
// groupIdentifier, // Throws an error in EAS
}),
};
}

Expand Down
7 changes: 6 additions & 1 deletion plugin/src/withEntitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const withEntitlements: ConfigPlugin<{
targetName: string;
groupIdentifier: string;
appleSignin: boolean;
}> = (config, { targetName, groupIdentifier, appleSignin }) => {
applePayMerchantIds: string[];
}> = (
config,
{ targetName, groupIdentifier, appleSignin, applePayMerchantIds },
) => {
return withInfoPlist(config, (config) => {
const targetPath = path.join(
config.modRequest.platformProjectRoot,
Expand All @@ -24,6 +28,7 @@ export const withEntitlements: ConfigPlugin<{
const appClipEntitlements = getAppClipEntitlements(config.ios, {
groupIdentifier,
appleSignin,
applePayMerchantIds,
});

fs.mkdirSync(path.dirname(filePath), { recursive: true });
Expand Down

0 comments on commit 4b56a95

Please sign in to comment.