I'm trying to incorporate Stripe payments into my Xamarin app. I've installed the latest Stripe NuGet Package and have included the following code in my .cs:
using System;
using System.Collections.Generic;
using Stripe;
using Xamarin.Forms;
namespace CampaignFinanceNew
{
public partial class CreditCardProcess : ContentPage
{
StripeClient paymentClient = new StripeClient("[test key here]");
public CreditCardProcess()
{
InitializeComponent();
CreditCard currentCard = new CreditCard();
currentCard.Number = creditCardNumber.Text;
currentCard.ExpMonth = Convert.ToInt32(ccExpiryMonth.Text);
currentCard.ExpYear = Convert.ToInt32(ccExpiryYear.Text);
StripeObject newToken = paymentClient.CreateCardToken(currentCard);
}
}
}
When I build the project, it gives me the following error:
Error XA2002: Can not resolve reference: Stripe, referenced by CampaignFinanceNew. Please add a NuGet package or assembly reference for Stripe, or remove the reference to CampaignFinanceNew. (XA2002) (CampaignFinanceNew.Android)
I've tried to add the Stripe package to both my iOS and Android projects, but it tells me that it's incompatible. What should I do? Would I be better off implementing it individually for both iOS and Android then just accessing it via DependencyService?
Upon further research, it appears there are 2 different Stripe NuGet Packages, one specifically written for .NET applications (as opposed to the one I was using). I've downloaded the new package and things seem to be working fine now.
Related
I have an android aar which is used in ReactNative and Xamarin android. I need to find the native api is called from which hybrid framework. For ReactNative I used Class reactClass = Class.forClass("com.facebook.react.ReactActivity") , if reactClass is not null then it was called from ReactNative. How do I find for Xamarin
Do you try to do like below ?
Java.Lang.Class.FromType(typeof(YourClass)).Name
This is the exact same problem presented in this question: Unity Firebase is not initializing on Android
But the solution to that one doesn't work for me because the code is different.
When I run the app in Unity, Firebase is initialized correctly, but when I build the app, for Android or PC, it doesn't initialize.
I write my code from this tutorial: https://www.youtube.com/watch?v=A6du3DUTIPI
using System;
using System.Collections;
using System.Collections.Generic;
using Firebase;
using Firebase.Analytics;
using Firebase.Extensions;
using UnityEngine;
using UnityEngine.Events;
public class FirebaseInit : MonoBehaviour
{
public UnityEvent OnFirebaseInitialized = new UnityEvent();
private void Start()
{
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
if (task.Exception != null)
{
Debug.LogError($"Error al inicializar Firebase con {task.Exception}");
return;
}
OnFirebaseInitialized.Invoke();
});
}
}
I have Unity 2019.4.4f1 and the latest Firebase SDK
I found a solution, but without fixing the actual problem.
I installed the Unity Editor using the offline installation, so it appears that this method doesn't download all the needed Android dependencies, because I tried installing again the Editor, but through the Unity Hub this time and the problem disappeared.
I've been trying to write a library in kotlin and once the library build is generated as aar file when opening it in Android Studio it is not showing me how my class exactly looks and how the methods are implemented in that.
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.mypackage.dexter
public final class Test private constructor() {
public final fun testMethod(): kotlin.Unit { /* compiled code */ }
}
I've tried Java decompiler plugin in android studio, Kotlin Byte code (This also doesn't show it in the same format that we get if the same code is written in Java). The ultimate thing that I wanted to achieve by looking at the code is that I want to use debugger in the library and evaluate things while running my application where this library is integrated.
I'm trying to use this package in my react native project.
So far I've followed all the steps in their installation guide and I made it work on iOS.
However, on Android, every time I try to import Batch or BatchPush in my code like this:
import { BatchPush, Batch } from "#bam.tech/react-native-batch";
I get an error on Android only:
null is not an object (evaluating 'RNBatch.NOTIFICATION_TYPES')
So when I go to node_modules/#bam.tech/react-native-batch/dist/BatchPush.js I see this
const RNBatch = react_native_1.NativeModules.RNBatch;
exports.AndroidNotificationTypes = RNBatch.NOTIFICATION_TYPES;
So somehow the native module is not being imported correctly. Do I need to follow extra steps for this to work?
#bam.tech/react-native-batch is being used with version 5.2.1
npm version 6.14.7
react-native version 0.60.5
Update: it turns out that the package was not linked correctly and that I had to manually add the package in MainApplication.java (I don't know why react-native link did not add this automatically)
Add the import:
import tech.bam.RNBatchPush.RNBatchPackage;
And then add
new RNBatchPackage(), in the getPackages() method.
I am written a very simple plugin which get all the messages from android device and pack it to response. When I am using npm install ionic-capacitor-sms-access and trying to access messages it just call web method but not the android method. So its not working can someone help me here and tell me what went wrong?
Here is my plugin https://www.npmjs.com/package/ionic-capacitor-sms-access
(Note: only the android folder)
It works, there are two ways to achieve this.
Method 1 (from the official tutorial)
What you need to do is just to keep following that tutorial to the section of 'Custom JavaScript', where shows demonstrates how to use your plugin within your ionic/typescripts codes.
such as:
import { Plugins } from '#capacitor/core';
const { SuperGreatPlugin } = Plugins;
export class CustomSuperPlugin {
constructor() {
}
customAwesomeness() {
SuperGreatPlugin.awesome();
}
}
Notes:
the name of the plugin class, i.e. 'SuperGreatPlugin' must be same with your java class for the plugin.
Method 2 (javascript way)
You can also import your plugin from the npm package you published. But be aware of the first line of the generated definitions.ts, declare module "#capacitor/core". This means you have to find your plugin from the specific module, here it is 'Plugins' as other plugins usage.
The following is the method 2:
import { SuperGreatPlugin } from 'YOUR_PLUGIN_NPM_PACKAGE';
async pluginEcho() {
await Plugins.SuperGreatPlugin.echo({value: 'bla bla bla'})
}
call the function pluginEcho() in your ionic page.
When I started I head really trouble distinguishing the web and native plugin but finally I understand that they are completely separated.
I recommend to rename the exported web plugin object in your web.ts file and add Web in the name. For me this was also necessary in order to not have compile errors.
TS2308: Module './definitions' has already exported a member named 'YourPlugin'. Consider explicitly re-exporting to resolve the ambiguity.
If you want to use your web plugin you import and use it like:
import { YourWebPlugin } from 'YOUR_PLUGIN_NPM_PACKAGE';
YourWebPlugin.callSomething();
If you want to use the native plugin you import and use it like:
import { Plugins } from '#capacitor/core';
const { YourPlugin } = Plugins;
YourPlugin.callSomething();
Don't forget to expose your native plugin to your android app project where you use your custom plugin
https://capacitor.ionicframework.com/docs/plugins/android#export-to-capacitor