1

我正在尝试在带有 pyjnius 的 Kivy 应用程序中使用 Stripe 支付 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 具有多个构造函数选项的事实有关。下面是我的代码。(卡上的崩溃 = Card(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)
4

1 回答 1

1

通过将输入变量转换为字符串和整数来修复

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)
于 2018-04-09T21:59:20.273 回答