# Path: openunipay/ali_pay/security.py
# def sign(data):
# def verify(data, sign, pemKeyfile):
# def verify_ali_data(valueDict):
# def _load_private_key(pemKeyfile):
# def _load_public_key(pemKeyfile):


from django.db import models
from django.conf import settings
from urllib.parse import quote_plus
from openunipay.ali_pay import security

        verbose_name = u'支付宝订单'
        verbose_name_plural = u'支付宝订单'
        
    def __str__(self):
        return self.out_trade_no
        
    def compose_interface_data(self):
        # sign data
        data = self._compose_data()
        return '{}&sign_type="RSA"&sign="{}"'.format(data, quote_plus(security.sign(data)))
    
    def _compose_data(self):
        valueDict = {item:getattr(self, item) 
                for item in _ALIPAY_ORDER_FIELD 
                if getattr(self, item)}
        valueDict['service'] = _SERVICE
        valueDict['_input_charset'] = _CHARSET
        valueDict['payment_type'] = _PAYMENT_TYPE
        valueDict['partner'] = settings.ALIPAY['partner']
        valueDict['seller_id'] = settings.ALIPAY['seller_id']
        valueDict['notify_url'] = settings.ALIPAY['notify_url']
        
        temp = []
        for key in valueDict:
            if not valueDict[key]:
                continue
            temp.append('{}="{}"'.format(key, valueDict[key]))
        tempStr = '&'.join(temp)
        return tempStr
    

# Path: openunipay/ali_pay/security.py
# def sign(data):
# def verify(data, sign, pemKeyfile):
# def verify_ali_data(valueDict):
# def _load_private_key(pemKeyfile):
# def _load_public_key(pemKeyfile):


# Path: openunipay/ali_pay/models.py
from django.db import models
from django.conf import settings
from urllib.parse import quote_plus
from openunipay.ali_pay import security

        verbose_name = u'支付宝订单'
        verbose_name_plural = u'支付宝订单'
        
    def __str__(self):
        return self.out_trade_no
        
    def compose_interface_data(self):
        # sign data
        data = self._compose_data()
        return '{}&sign_type="RSA"&sign="{}"'.format(data, quote_plus(security.sign(data)))
    
    def _compose_data(self):
        valueDict = {item:getattr(self, item) 
                for item in _ALIPAY_ORDER_FIELD 
                if getattr(self, item)}
        valueDict['service'] = _SERVICE
        valueDict['_input_charset'] = _CHARSET
        valueDict['payment_type'] = _PAYMENT_TYPE
        valueDict['partner'] = settings.ALIPAY['partner']
        valueDict['seller_id'] = settings.ALIPAY['seller_id']
        valueDict['notify_url'] = settings.ALIPAY['notify_url']
        
        temp = []
        for key in valueDict:
            if not valueDict[key]:
                continue
            temp.append('{}="{}"'.format(key, valueDict[key]))
        tempStr = '&'.join(temp)
        return tempStr
    

class AliPayResult(models.Model):
