我正在尝试在带有pyjnius的Kivy应用中使用Stripe payment Android SDK。尝试从https://github.com/stripe/stripe-android/blob/v2.1.0/stripe/src/main/java/com/stripe/android/model/Card.java初始化Card.java时 我收到错误'jnius.jnius.JavaException:没有与你的参数匹配的构造函数'我认为这与Card.java有多个构造函数选项有关。这是我下面的代码。 (在卡上崩溃=卡(cardNum,expMon,expYear,cvc))
from jnius import autoclass,PythonJavaClass,cast,java_method
Stripe = autoclass('com.stripe.android.Stripe')
Card = autoclass('com.stripe.android.model.Card')
Token = autoclass('com.stripe.android.model.Token')
TokenCallback = autoclass('com.stripe.android.TokenCallback')
class StripeTokenCallback(PythonJavaClass):
__javainterfaces__ = ('com.stripe.android.TokenCallback',)
@java_method('([Lcom.stripe.android.model.Token;)V')
def onSuccess(self,token):
print 'printing token debug'
print token
Cipher = AESCipher.AESCipher(_key)
msg = '{"client_nonce:"' + token + '"}'
print msg
encMsg = Cipher.encrypt(msg)
rsp = connectToServer(_host, _port, encMsg)
decRsp = Cipher.decrypt(rsp)
pass
@java_method('[Ljava.lang.Exception;)V')
def onError(self,error):
print 'Error - Debug'
print error
pass
class StripeToken():
def __init__(self):
pass
def genToken(self,token,cardNum,expMon,expYear,cvc):
card = Card(cardNum,expMon,expYear,cvc)
if not card.validateCard():
print 'Card Not Valid'
return False
stripe = Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh")
token_cb = StripeTokenCallback()
stripe.createToken(card,token_cb)
答案 0 :(得分:0)
通过将输入变量转换为字符串和整数来修复
from jnius import autoclass,PythonJavaClass,cast,java_method
Integer = autoclass('java.lang.Integer')
String = autoclass('java.lang.String')
Stripe = autoclass('com.stripe.android.Stripe')
Card = autoclass('com.stripe.android.model.Card')
Token = autoclass('com.stripe.android.model.Token')
TokenCallback = autoclass('com.stripe.android.TokenCallback')
class StripeTokenCallback(PythonJavaClass):
__javainterfaces__ = ('com.stripe.android.TokenCallback',)
@java_method('([Lcom.stripe.android.model.Token;)V')
def onSuccess(self,token):
print 'printing token debug'
print token
Cipher = AESCipher.AESCipher(_key)
msg = '{"client_nonce:"' + token + '"}'
print msg
encMsg = Cipher.encrypt(msg)
rsp = connectToServer(_host, _port, encMsg)
decRsp = Cipher.decrypt(rsp)
pass
@java_method('[Ljava.lang.Exception;)V')
def onError(self,error):
print 'Error - Debug'
print error
pass
def genToken(token,cardNum,expMon,expYear,cvc):
jcardNum = cast('java.lang.String', String(cardNum))
jexpMon = cast('java.lang.Integer', Integer(expMon))
jexpYear = cast('java.lang.Integer', Integer(expYear))
jcvc = cast('java.lang.String', String(cvc))
card = Card(jcardNum,jexpMon,jexpYear,jcvc)
if not card.validateCard():
print 'Card Not Valid'
return False
stripe = Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh")
token_cb = StripeTokenCallback()
stripe.createToken(card,token_cb)