|
| 1 | +/** |
| 2 | + * Sample React Native App |
| 3 | + * https://github.com/facebook/react-native |
| 4 | + * |
| 5 | + * @format |
| 6 | + * @flow |
| 7 | + */ |
| 8 | + |
| 9 | +import React, {Component} from 'react'; |
| 10 | +import {Platform, StyleSheet, Text, View,Button} from 'react-native'; |
| 11 | + |
| 12 | +const instructions = Platform.select({ |
| 13 | + ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', |
| 14 | + android: |
| 15 | + 'Double tap R on your keyboard to reload,\n' + |
| 16 | + 'Shake or press menu button for dev menu', |
| 17 | +}); |
| 18 | + |
| 19 | +type Props = {}; |
| 20 | +export default class App extends Component<Props> { |
| 21 | + state = { |
| 22 | + string : "" |
| 23 | + }; |
| 24 | + |
| 25 | + buttonClicked(){ |
| 26 | + var c = this; |
| 27 | +var molpay = require("molpay-mobile-xdk-reactnative-beta"); |
| 28 | + var paymentDetails = { |
| 29 | + // Mandatory String. A value more than '1.00' |
| 30 | + 'mp_amount': 1.1, |
| 31 | + |
| 32 | + // Mandatory String. Values obtained from MOLPay |
| 33 | + 'mp_username': 'username', |
| 34 | + 'mp_password': 'password', |
| 35 | + 'mp_merchant_ID': 'merchantID', |
| 36 | + 'mp_app_name': 'appname', |
| 37 | + 'mp_verification_key': '12345123451234512345', |
| 38 | + |
| 39 | + // Mandatory String. Payment values |
| 40 | + 'mp_order_ID': 'React0002', |
| 41 | + 'mp_currency': 'MYR', |
| 42 | + 'mp_country': 'MY', |
| 43 | + |
| 44 | + // Optional String. |
| 45 | + 'mp_channel': '', // Use 'multi' for all available channels option. For individual channel seletion, please refer to "Channel Parameter" in "Channel Lists" in the MOLPay API Spec for Merchant pdf. |
| 46 | + 'mp_bill_description': 'test payment', |
| 47 | + 'mp_bill_name': 'anyname', |
| 48 | + 'mp_bill_email': 'example@email.com', |
| 49 | + 'mp_bill_mobile': '0161111111', |
| 50 | + // 'mp_channel_editing': true, // Option to allow channel selection. |
| 51 | + 'mp_editing_enabled': true, // Option to allow billing information editing. |
| 52 | + |
| 53 | + // Optional for Escrow |
| 54 | + // 'mp_is_escrow': '', // Optional for Escrow, put "1" to enable escrow |
| 55 | + |
| 56 | + // Optional for credit card BIN restrictions |
| 57 | + //'mp_bin_lock': ['414170', '414171'], // Optional for credit card BIN restrictions |
| 58 | + //'mp_bin_lock_err_msg': 'Only UOB allowed', // Optional for credit card BIN restrictions |
| 59 | + |
| 60 | + // For transaction request use only, do not use this on payment process |
| 61 | + // 'mp_transaction_id': '', // Optional, provide a valid cash channel transaction id here will display a payment instruction screen. |
| 62 | + // 'mp_request_type': '', // Optional, set 'Status' when doing a transactionRequest |
| 63 | + |
| 64 | + // Optional, use this to customize the UI theme for the payment info screen, the original XDK custom.css file is provided at Example project source for reference and implementation. |
| 65 | + // 'mp_custom_css_url': '', |
| 66 | + |
| 67 | + // Optional, set the token id to nominate a preferred token as the default selection, set "new" to allow new card only |
| 68 | + // 'mp_preferred_token': '', |
| 69 | + |
| 70 | + // Optional, credit card transaction type, set "AUTH" to authorize the transaction |
| 71 | + // 'mp_tcctype': '', |
| 72 | + |
| 73 | + // Optional, set true to process this transaction through the recurring api, please refer the MOLPay Recurring API pdf |
| 74 | + // // 'mp_is_recurring': false, |
| 75 | + |
| 76 | + // Optional for channels restriction |
| 77 | + // 'mp_allowed_channels': ['credit','credit3'], |
| 78 | + |
| 79 | + // Optional for sandboxed development environment, set boolean value to enable. |
| 80 | + // 'mp_sandbox_mode': false, |
| 81 | + |
| 82 | + // Optional, required a valid mp_channel value, this will skip the payment info page and go direct to the payment screen. |
| 83 | + // 'mp_express_mode': false, |
| 84 | + // "mp_bill_description_edit_disabled": false, |
| 85 | + |
| 86 | +}; |
| 87 | + // start molpay payment |
| 88 | + molpay.startMolpay(paymentDetails,function(data){ |
| 89 | + console.log(data); |
| 90 | + //console.log(paymentDetails); |
| 91 | + console.log(this); |
| 92 | + alert(JSON.stringify(data)); |
| 93 | + //callback after payment success |
| 94 | + c.setState({ |
| 95 | + string : data |
| 96 | + }) |
| 97 | + |
| 98 | + }); |
| 99 | +}; |
| 100 | + |
| 101 | + render() { |
| 102 | + return ( |
| 103 | + <View style={styles.container}> |
| 104 | + <Text style={styles.welcome}>Welcome to React Native!</Text> |
| 105 | + <Text style={styles.instructions}>To get started, edit App.js</Text> |
| 106 | + <Text style={styles.instructions}>{instructions}</Text> |
| 107 | + <Text style={styles.instructions}>{this.state.string}</Text> |
| 108 | + <Button |
| 109 | + style={{backgroundColor: 'grey', flex: 0.5}} |
| 110 | + onPress={this.buttonClicked.bind(this)} |
| 111 | + title="Start Molpay" /> |
| 112 | + </View> |
| 113 | + ); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +const styles = StyleSheet.create({ |
| 118 | + container: { |
| 119 | + flex: 1, |
| 120 | + justifyContent: 'center', |
| 121 | + alignItems: 'center', |
| 122 | + backgroundColor: '#F5FCFF', |
| 123 | + }, |
| 124 | + welcome: { |
| 125 | + fontSize: 20, |
| 126 | + textAlign: 'center', |
| 127 | + margin: 10, |
| 128 | + }, |
| 129 | + instructions: { |
| 130 | + textAlign: 'center', |
| 131 | + color: '#333333', |
| 132 | + marginBottom: 5, |
| 133 | + }, |
| 134 | +}); |
0 commit comments