Skip to content

Commit 793ac34

Browse files
Enable programmatic submission via Frames ref (submitCard); update docs, tests, and dependencies (#49)
* Update dependencies and improve integration tests - Bump `expo` and `babel-preset-expo` versions in `package.json` and `package-lock.json`. - Upgrade `jest-expo` to match the new `expo` version. - Refactor integration tests for `Frames` component to mock network requests and improve validation checks. - Remove redundant tests and ensure proper error handling for card tokenization. - Add new tests for billing details and card validation events. * Refactor Frames component and update TypeScript types - Simplified state initialization in the Frames component by defining initialState separately. - Updated TypeScript types to allow null values for card-related fields in FramesState. - Changed autoCompleteType to autoComplete in CardNumber, Cvv, and ExpiryDate components for better compatibility. - Ensured safe access to state properties by using nullish coalescing in input values. - Refactored framesReducer to use a more explicit action parameter for better type safety. * Enhance Frames component with programmatic submission and update tests - Updated the Frames component to support programmatic card submission via a ref using `submitCard()`. - Modified README to include new usage example for programmatic submission. - Adjusted integration tests to validate the new submission method and ensure proper tokenization. - Updated public key in tests and other files for consistency. * Update version to 1.2.3 and refine GitHub Actions workflow - Bumped package version from 1.2.2 to 1.2.3 in package.json. - Improved formatting and structure of the GitHub Actions workflow in cd.yml for better readability and maintainability. - Added conditional execution for the publish-npm job to ensure it only runs on pushes to the main branch.
1 parent caa8a1f commit 793ac34

16 files changed

Lines changed: 4080 additions & 5484 deletions

File tree

.github/workflows/cd.yml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
name: Test and Deploy
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
1010

1111
jobs:
12-
test-and-coverage:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- uses: actions/checkout@master
16-
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: 21
20-
- run: npm ci
21-
- run: npm test
22-
- name: Upload coverage to Codecov
23-
uses: codecov/codecov-action@v1
24-
with:
25-
token: ${{ secrets.CODECOV_TOKEN }}
26-
verbose: true
12+
test-and-coverage:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 21
19+
- run: npm ci
20+
- run: npm test
21+
- name: Upload coverage to Codecov
22+
uses: codecov/codecov-action@v1
23+
with:
24+
token: ${{ secrets.CODECOV_TOKEN }}
25+
verbose: true
2726

28-
publish-npm:
29-
needs: test-and-coverage
30-
runs-on: ubuntu-latest
31-
steps:
32-
- uses: actions/checkout@v4
33-
- uses: actions/setup-node@v4
34-
with:
35-
node-version: 21
36-
registry-url: https://registry.npmjs.org/
37-
- run: npm ci
38-
- run: npm run build
39-
- run: cp -R src/icons dist/
40-
- run: npm publish
41-
env:
42-
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
27+
publish-npm:
28+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
29+
needs: test-and-coverage
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version: 21
36+
registry-url: https://registry.npmjs.org/
37+
- run: npm ci
38+
- run: npm run build
39+
- run: cp -R src/icons dist/
40+
- run: npm publish
41+
env:
42+
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function App() {
5757
<Frames
5858
config={{
5959
debug: true,
60-
publicKey: "pk_test_4296fd52-efba-4a38-b6ce-cf0d93639d8a",
60+
publicKey: "pk_sbox_eo3yb3urja2ozf6ycgn5kuy7ke#",
6161
}}
6262
cardTokenized={(e) => {
6363
alert(e.token);
@@ -144,7 +144,41 @@ const styles = StyleSheet.create({
144144

145145
## Trigger tokenization
146146

147-
The tokenization is triggered when the SubmitButton is pressed. The process of getting the token is async, so the outcome of the tokenization will be shared in the _cardTokenized_ or _cardTokenizationFailed_ handlers.
147+
The tokenization is triggered when the `SubmitButton` is pressed, or programmatically via a ref on `Frames`.
148+
149+
### Programmatic submit via ref
150+
151+
You can attach a ref to `Frames` and call `submitCard()` imperatively:
152+
153+
```tsx
154+
import React, { useRef } from "react";
155+
import { Frames, CardNumber, ExpiryDate, Cvv } from "frames-react-native";
156+
import type { FramesRef } from "frames-react-native";
157+
158+
export const Example = () => {
159+
const framesRef = useRef<FramesRef>(null);
160+
161+
const onCustomPress = () => {
162+
framesRef.current?.submitCard();
163+
};
164+
165+
return (
166+
<Frames
167+
ref={framesRef}
168+
config={{ debug: true, publicKey: "pk_test_..." }}
169+
cardTokenized={(e) => console.log(e.token)}
170+
>
171+
<CardNumber />
172+
<ExpiryDate />
173+
<Cvv />
174+
{/* Use your own button UI */}
175+
<MyCustomButton onPress={onCustomPress} />
176+
</Frames>
177+
);
178+
};
179+
```
180+
181+
The process of getting the token is async, so the outcome of the tokenization will be shared in the `cardTokenized` or `cardTokenizationFailed` handlers.
148182

149183
## The `props` for the Frames wrapper component
150184

0 commit comments

Comments
 (0)