Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding capture_payment after process #52

Merged
merged 6 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion e2e/app.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ describe('Payments', () => {
await checkIfLogExist('removeCard');
await checkIfLogExist('Collected');
await checkIfLogExist('Process');
await checkIfLogExist('Finished');
await checkIfLogExist('Processed');
await checkIfLogExist('Capture');
await checkIfLogExist('Captured');
});

it('Store card via readReusableCard', async () => {
Expand Down
48 changes: 47 additions & 1 deletion example/src/screens/CollectCardPaymentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ export default function CollectCardPaymentScreen() {
return { client_secret, id, error: null };
};

const capturePaymentIntent = async (id: string) => {
const response = await fetch(`${API_URL}/capture_payment_intent`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id }),
});
return await response.json();
};

const _createPaymentIntent = async () => {
clearLogs();
navigation.navigate('LogListScreen');
Expand Down Expand Up @@ -212,12 +223,47 @@ export default function CollectCardPaymentScreen() {
name: 'Process Payment',
events: [
{
name: 'Finished',
name: 'Processed',
description: 'terminal.processPayment',
metadata: { paymentIntentId },
},
],
});
_capturePayment(paymentIntentId);
}
};

const _capturePayment = async (paymentIntentId: string) => {
addLogs({
name: 'Capture Payment',
events: [{ name: 'Capture', description: 'terminal.capturePayment' }],
});

const { intent, error } = await capturePaymentIntent(paymentIntentId);
if (error) {
addLogs({
name: 'Capture Payment',
events: [
{
name: 'Failed',
description: 'terminal.capturePayment',
metadata: {
errorCode: error.code,
errorMessage: error.message,
},
},
],
});
} else if (intent) {
addLogs({
name: 'Capture Payment',
events: [
{
name: 'Captured',
description: 'terminal.paymentIntentId: ' + intent.id,
},
],
});
}
};

Expand Down
3 changes: 2 additions & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"compilerOptions": {
"esModuleInterop": true,
"noEmit": true,
Copy link
Contributor Author

@jdivock-stripe jdivock-stripe Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need this to prevent generating *.js files when I was just trying to typecheck

"jsx": "react",
"paths": {
"stripe-terminal-react-native": ["../src/index"]
},
}
}
}