# React Native In-App Payment Integration - functional approach

**URL:** <https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331>\
**Category:** Questions\
**Tags:** in-app-payments-sdk\
**Created:** [November 30, 2020, 10:02pm UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331 "2020-11-30T22:02:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidHVernon](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@DavidHVernon](https://developer.squareup.com/forums/u/DavidHVernon)\
**Post date:** [November 30, 2020, 10:02pm UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/1 "2020-11-30T22:02:57Z")

</div>

I’ve gotten so much good feedback from the Square team (and others) on this forum, I figured I’d contribute something for the next guy.

One of the problems that I ran into while integrating in-app payments into my React Native app was the the examples all take the old school Object Oriented approach, and I (and most of the RN community) prefer a functional approach.

Since I am still new to RN, this took a bit of reading and experimentation (I’ve never learned the OO appraoches). The sample code below is close to what I landed on.

Simple to integrate: On the component that you will start credit card processing, merge in the code below.

This code is lifted verbatim (except for some logging) from Square docs and reordered slightly:

_[Getting Started with the React Native Plugin for In-App Payments SDK](https://github.com/square/in-app-payments-react-native-plugin/blob/master/docs/get-started.md#step-2-install-and-link-the-react-native-plugin-for-in-app-payments-sdk)_

```auto
...
import { SQIPCore, SQIPCardEntry } from 'react-native-square-in-app-payments';

...

const ReviewOrderScreen = ({ route, navigation }) => {

    // ...

    const onStartCardEntry = async () => {
        console.log('onStartCardEntry')

        await SQIPCore.setSquareApplicationId('sandbox-sq0idb-nyLT7WXGrzL-kk88hjhQRA');

        if (Platform.OS === 'ios') {
            await SQIPCardEntry.setIOSCardEntryTheme({
                saveButtonFont: {
                    size: 25,
                },
                saveButtonTitle: 'Pay 💳 ',
                keyboardAppearance: 'Light',
                saveButtonTextColor: {
                    r: 255,
                    g: 0,
                    b: 125,
                    a: 0.5,
                },
            });
        }

        await SQIPCardEntry.startCardEntryFlow(
            { collectPostalCode: false },
            onCardNonceRequestSuccess,
            onCardEntryCancel,
        );
    }

    const onCardNonceRequestSuccess = async (cardDetails) => {
        console.log('onCardNonceRequestSuccess')
        try {
            // take payment with the card details
            // await chargeCard(cardDetails);

            // payment finished successfully
            // you must call this method to close card entry
            await SQIPCardEntry.completeCardEntry(
                this.onCardEntryComplete(),
            );
        } catch (ex) {
            // payment failed to complete due to error
            // notify card entry to show processing error
            await SQIPCardEntry.showCardNonceProcessingError(ex.message);
        }
    }

    const onCardEntryComplete = () => {
        console.log('onCardEntryComplete')
    }

    const onCardEntryCancel = () => {
        console.log('onCardEntryCancel')
    }

    // ...

    return (

        // ...

        < ... onPress={() => { onStartCardEntry() } ... />

        // ...
    )
}

```

Submitted in the hopes that someone will find it helpful.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 1, 2020, 12:17am UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/2 "2020-12-01T00:17:50Z")

</div>

Thank you for sharing with the community!

---

<div class="post-metadata">

**Author:** ![ShirishSharma](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@ShirishSharma](https://developer.squareup.com/forums/u/ShirishSharma)\
**Post date:** [December 3, 2020, 5:43am UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/3 "2020-12-03T05:43:26Z")

</div>

Thank you for sharing this. I need your guidance on integration of Square Payment with iOnic app as well. you can find more details here - [Integration with iOnic apps](https://developer.squareup.com/forums/t/integration-with-ionic-apps/832/12)

---

<div class="post-metadata">

**Author:** ![DavidHVernon](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@DavidHVernon](https://developer.squareup.com/forums/u/DavidHVernon)\
**Post date:** [December 3, 2020, 3:40pm UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/4 "2020-12-03T15:40:05Z")

</div>

Shirish - I had a lot of trouble getting in-app credit card processing working. Mostly the confusion was from the example code. Once I ditched that and just dug into the API Docs things got better.

I have some notes on this. I’ll drop them in this topic later in the day.

---

<div class="post-metadata">

**Author:** ![DavidHVernon](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@DavidHVernon](https://developer.squareup.com/forums/u/DavidHVernon)\
**Post date:** [December 3, 2020, 3:41pm UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/5 "2020-12-03T15:41:27Z")

</div>

PS - Never heard of IOnick. Can’t help there at all.

---

<div class="post-metadata">

**Author:** ![ShirishSharma](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@ShirishSharma](https://developer.squareup.com/forums/u/ShirishSharma)\
**Post date:** [December 3, 2020, 4:57pm UTC](https://developer.squareup.com/forums/t/react-native-in-app-payment-integration-functional-approach/1331/6 "2020-12-03T16:57:50Z")

</div>

ionic, flutter are some of the popular framework for iOS and android app development. You can think those as the non native framework.
