# 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

# -*- coding: utf-8 -*-

_SERVICE = 'mobile.securitypay.pay'
_CHARSET = 'utf-8'
_SIGN_TYPE = 'RSA'
_PAYMENT_TYPE = '1'

_ALIPAY_ORDER_FIELD = ('out_trade_no', 'subject', 'body', 'total_fee', 'it_b_pay',)

class AliPayOrder(models.Model):
    out_trade_no = models.CharField(verbose_name='商户订单号', max_length=32, db_index=True, editable=False)
    subject = models.CharField(verbose_name='商品名称', max_length=128, editable=False)
    body = models.CharField(verbose_name='商品详情', max_length=512, editable=False)
    total_fee = models.DecimalField(verbose_name='总金额(单位:元)', max_digits=6, decimal_places=2, editable=False)
    it_b_pay = models.CharField(verbose_name='交易有效期', max_length=19, editable=False)
    date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
    
    class Meta:
        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()

# 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

# -*- coding: utf-8 -*-

_SERVICE = 'mobile.securitypay.pay'
_CHARSET = 'utf-8'
_SIGN_TYPE = 'RSA'
_PAYMENT_TYPE = '1'

_ALIPAY_ORDER_FIELD = ('out_trade_no', 'subject', 'body', 'total_fee', 'it_b_pay',)

class AliPayOrder(models.Model):
    out_trade_no = models.CharField(verbose_name='商户订单号', max_length=32, db_index=True, editable=False)
    subject = models.CharField(verbose_name='商品名称', max_length=128, editable=False)
    body = models.CharField(verbose_name='商品详情', max_length=512, editable=False)
    total_fee = models.DecimalField(verbose_name='总金额(单位:元)', max_digits=6, decimal_places=2, editable=False)
    it_b_pay = models.CharField(verbose_name='交易有效期', max_length=19, editable=False)
    date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
    
    class Meta:
        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)))
