conekta-capacitor
A Capacitor plugin for Conekta, that supports Capacitor 2.0
Supported platforms
The plugin supports JS, Android and iOS exposing the Conekta SDK functionalities. Here is the official Conekta documentation for the SDK's.
Installation
npm install -s conekta-capacitor
If you are working on a framework like Quasar, the package should be installed in the Quasar project and installed again in the capacitor project (inside src-capacitor), so you could use the JS implementation within Quasar and the native version within Capacitor's project. Here is a [Quasar example](link to quasar)
Note: Remember that after installation an npx cap sync
call could be needed.
Extra steps for Android
As per the Capacitor docs the plugin should be added to the app MainActivity.
The next line should be added to your app MainActivity
add(com.villavanilla.conekta.capacitor.ConektaPlugin.class);
The full code should look something like this:
// Other imports...
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(com.villavanilla.conekta.capacitor.ConektaPlugin.class);
}});
}
}
Usage
import { Plugins } from '@capacitor/core'
const { ConektaPlugin } = Plugins
import 'conekta-capacitor'
Exposed methods:
ConektaPlugin.setPublicKey({ key: string }): Promise<void>;
ConektaPlugin.getPublicKey(): Promise<{ key: string }>;
ConektaPlugin.setLanguage({ language: string }): Promise<void>;
ConektaPlugin.getLanguage(): Promise<{ language: string }>;
ConektaPlugin.createToken({ number: string, name: string, cvc: string, exp_month: string, exp_year: string }): Promise<any>;
ConektaPlugin.setApiVersion({ api_version: string }): Promise<void>;
ConektaPlugin.getApiVersion(): Promise<{ api_version: string }>;
ConektaPlugin.deviceFingerPrint(): Promise<{ fingerprint: string }>
ConektaPlugin.getBaseUri(): Promise<{ uri: string }>;
The most important action is the token creation
Here is an example:
import { Plugins } from '@capacitor/core'
const { ConektaPlugin } = Plugins
import 'conekta-capacitor'
ConektaPlugin.setPluginKey({key:"[YOUR_CONEKTA_KEY]"})
let card = {
number: 'Card number',
name: 'Card name',
cvc: 'Card CVC',
exp_month: 'Card expiration month',
exp_year: 'Card expiration year',
}
try{
let result = await ConektaPlugin.createToken(card)
console.log(`Here is your token: ${result.id}`)
}catch(error){
console.log(error)
}