Skip to content

Commit

Permalink
Improve code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodelpupo committed Jun 7, 2024
1 parent b99ece5 commit e60173d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cd ios && pod install

## How it works

Integrations in React Native must inform the `integrationContext` parameter with the value `InAppBrowserNotify` in the establish data, as in the example below:
Integrations in React Native must inform the `integrationContext` parameter with the value `InAppBrowserNotify` in the `establishData`, as in the example below:

```javascript
let establishData = {
Expand All @@ -38,7 +38,7 @@ let establishData = {
};
```

After that, when an OAuth bank is selected in the Trustly Lightbox, a message will be triggered and must be captured by the `onMessage` attribute of the WebView, as in the example below (and in the App.tsx file):
After that, when an OAuth bank is selected in the Trustly Lightbox, a message will be triggered and must be captured by the `onMessage` attribute of the WebView, as in the example below (and in the `App.tsx` file):

```js
<WebView
Expand All @@ -48,7 +48,7 @@ After that, when an OAuth bank is selected in the Trustly Lightbox, a message wi
/>
```

The function informed in `onMessage` will receive the message with a URL that must be opened in an in-app browser, as in the example below (and in the App.tsx file):
The function informed in `onMessage` will receive the message with a URL that must be opened in an in-app browser, as in the example below (and in the `App.tsx` file):

```javascript
handleOAuthMessage = (message: any) => {
Expand All @@ -72,30 +72,30 @@ handleOAuthMessage = (message: any) => {

### RedirectActivity

When the application receives some action like `in-app-browser-rn` (or any name that you defined in the `urlScheme`), it will call your target Activity with some flags, and reload it.
When the application receives some action like `in-app-browser-rn` (or any name that you defined in the `urlScheme`), it will call your target `Activity` with some flags, and reload it.

The example below is from `RedirectActivity`:

```java
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
```

### AndroidManifest

```xml
<activity
android:name=".RedirectActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="in-app-browser-rn" />
</intent-filter>
</activity>
<activity
android:name=".RedirectActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="in-app-browser-rn" />
</intent-filter>
</activity>
```

## How to integrate native components with Trustly WebView
Expand All @@ -104,7 +104,7 @@ Trustly UI offers two types of user experiences that can be configured to fit yo

<img src="docs/images/rn_print.png" width="25%" height="25%" style="display: block; margin: 0 auto" />

In this case, we need to avoid the Widget calling the Lightbox immediately when the user selects a bank because we need to get the amount value to fill the establish data first. To achieve this, we need to add a piece of JavaScript inside the Widget (as in the `trustly.tsx` file).
In this case, we need to avoid the Widget calling the Lightbox immediately when the user selects a bank because we need to get the `amount` value to fill the `establishData` first. To achieve this, we need to add a piece of JavaScript inside the Widget (as in the `trustly.tsx` file).

```js
const TrustlyWidgetBankSelected = (data) => {
Expand All @@ -120,7 +120,7 @@ Now, you must implement in your WebView a way to handle the 3 events triggered b

```js
handlePaymentProviderId(data: string) {
if(data.startsWith('PayWithMyBank.createTransaction')) {
if (data.startsWith('PayWithMyBank.createTransaction')) {
let splitData = data.split('|')

this.establishData.amount = this.state.amount;
Expand All @@ -131,7 +131,7 @@ handlePaymentProviderId(data: string) {
}

goToAuthBankSelected = () => {
this.setState({step: 'lightbox'});
this.setState({ step: 'lightbox' });
}
```

Expand All @@ -140,7 +140,7 @@ goToAuthBankSelected = () => {
```js
handleWithCancelOrClose(data: string) {
if(data.endsWith('close|cancel|')) {
this.setState({step: 'widget'});
this.setState({ step: 'widget' });
}
}
```
Expand All @@ -149,7 +149,7 @@ handleWithCancelOrClose(data: string) {

```js
handleClosePanelSuccess(data: string) {
if(data.startsWith('PayWithMyBank.closePanel|')) {
if (data.startsWith('PayWithMyBank.closePanel|')) {
let returnValues = data.split('|')[1];
let returnParameters = returnValues.split('?')[1];

Expand Down

0 comments on commit e60173d

Please sign in to comment.