0.21.4 • Published 6 years ago

reduxable-kiwi-subscription v0.21.4

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

reduxable-kiwi-subscription

Reduxable for Kiwi and Google Play subscription

Install

$ yarn add reduxable-kiwi-subscription

Also you'll need two install and link other peer dependencies.

Android

iOS

Usage

First define and configure the reduxable

// store.js
import { SubscriptionReduxable } from 'reduxable-kiwi-subscription';

const config = {
  playStoreSku: 'purchase-item-id',
  iosProductId: 'com.your.product.id',
  handlers: {
    onStepChange: data => console.warn('onStepChange', data),
    onFlowClose: () => console.warn('onFlowClose'),
    onFlowStart: () => console.warn('onFlowStart'),
    onFlowFinish: () => console.warn('onFlowFinish'),
    onUnsubscribe: () => console.warn('onUnsubscribe'),
    onFirstTimeSubscriptionWithSMS: () => console.warn('onFirstTimeSubscriptionWithSMS'),
    onRestoreSubscriptionWithSMS: () => console.warn('onRestoreSubscriptionWithSMS'),
    onSubscriptionWithPlayStore: () => console.warn('onSubscriptionWithPlayStore'),
    onShowLegalsRequest: (title, url, htmlSelector) => console.warn('onShowLegalsRequest'),
  },
  translations: {
    es: {
      unsubscribeStep: {
        headerText: '(ES) Unsubscribe header',
      }
    },
    pt: {
      unsubscribeStep: {
        headerText: '(PT) Unsubscribe header',
      }
    }
  }
}

export const subscription = new SubscriptionReduxable(config);

// In your reducers import `combineReducers` and `createStore` from `reduxable` instead of `redux`

createStore(combineReducers({
  ...,
  subscription,
}))

Then in you view use the SubscriptionModal component, assuming this is already connected to the store and wrapped with <Provider> component.

// MySubscriptionFlow.js
import { SubscriptionModal } from 'reduxable-kiwi-subscription';
import { subscription } from '@store';

class Example extends Component {
  componentDidMount() {
    subscription.startFlow();
    // or also
    // subscription.startCodeRedeemFlow()
  }

  render() {
    const colors = {
      modalOuterBackground: 'black',
      modalInnerBackground: 'white',
      background: 'white',
      text: 'black',
      buttonBackground: 'red',
      buttonText: 'white',
      inputUnderline: 'red',
    };

    const modalHeader = <View style={{backgroundColor: 'red', height: 70}} />
    const modalBackground = <View style={{backgroundColor: '#EEEEEE', flex: 1 }} />
    
    const benefits = [
      '- Get the best news',
      '- See cool videos',
      '- Know more about your heroes'
    ]

    return (
      <View>
        <SubscriptionModal
          modalHeader={modalHeader}
          modalBackground={modalBackground}
          colors={colors}
          subscription={subscription}
          benefits={benefits}
          fontFamily="monospace" // optional
          renderButton={(text, onPress) => <Button title={text} onPress={onPress} />} // optional
          renderBenefitsContent={() => <View />} // optional 
        /> 
      </View>
    );
  }
}

Methods

checkSubscription()

To check if a user is subscribed you should call to checkSubscription(). For iOS you must pass a receiptValidator function like following.

const iosReceiptValidator = async (productId, receipt) {
  // Send `productId` and `receipt` to a server for receipt validation
  // The server must return a JSON like { "valid": true | false }
}

const isSubscribed = await subscription.checkSubscription(iosReceiptValidator)

License

MIT

0.21.4

6 years ago

0.21.3

6 years ago

0.21.2

6 years ago

0.21.1

6 years ago

0.21.0

6 years ago

0.20.0

6 years ago

0.19.2

6 years ago

0.19.1

6 years ago

0.19.0

6 years ago

0.18.0

6 years ago

0.17.1

6 years ago

0.17.0

6 years ago

0.16.0

6 years ago

0.15.0

6 years ago

0.13.1

6 years ago

0.14.0

6 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.8.0-9

6 years ago

0.8.0-8

6 years ago

0.8.0-7

6 years ago

0.8.0-6

6 years ago

0.8.0-5

6 years ago

0.8.0-4

6 years ago

0.8.0-3

6 years ago

0.8.0-2

6 years ago

0.8.0-1

6 years ago

0.8.0-0

6 years ago

0.7.1-3

7 years ago

0.7.1-2

7 years ago

0.7.1-1

7 years ago

0.7.1-0

7 years ago

0.7.0

7 years ago

0.7.0-4

7 years ago

0.7.0-3

7 years ago

0.7.0-2

7 years ago

0.7.0-1

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.6.1-5

7 years ago

0.6.1-4

7 years ago

0.6.1-3

7 years ago

0.6.1-2

7 years ago

0.6.1-1

7 years ago

0.6.1-0

7 years ago

0.6.0-0

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago