AlipayTradeOrderPayModel.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. from alipay.aop.api.domain.BuyerPayDetail import BuyerPayDetail
  6. class AlipayTradeOrderPayModel(object):
  7. def __init__(self):
  8. self._buyer_id = None
  9. self._buyer_pay_detail = None
  10. self._product_code = None
  11. self._total_amount = None
  12. self._trade_no = None
  13. @property
  14. def buyer_id(self):
  15. return self._buyer_id
  16. @buyer_id.setter
  17. def buyer_id(self, value):
  18. self._buyer_id = value
  19. @property
  20. def buyer_pay_detail(self):
  21. return self._buyer_pay_detail
  22. @buyer_pay_detail.setter
  23. def buyer_pay_detail(self, value):
  24. if isinstance(value, list):
  25. self._buyer_pay_detail = list()
  26. for i in value:
  27. if isinstance(i, BuyerPayDetail):
  28. self._buyer_pay_detail.append(i)
  29. else:
  30. self._buyer_pay_detail.append(BuyerPayDetail.from_alipay_dict(i))
  31. @property
  32. def product_code(self):
  33. return self._product_code
  34. @product_code.setter
  35. def product_code(self, value):
  36. self._product_code = value
  37. @property
  38. def total_amount(self):
  39. return self._total_amount
  40. @total_amount.setter
  41. def total_amount(self, value):
  42. self._total_amount = value
  43. @property
  44. def trade_no(self):
  45. return self._trade_no
  46. @trade_no.setter
  47. def trade_no(self, value):
  48. self._trade_no = value
  49. def to_alipay_dict(self):
  50. params = dict()
  51. if self.buyer_id:
  52. if hasattr(self.buyer_id, 'to_alipay_dict'):
  53. params['buyer_id'] = self.buyer_id.to_alipay_dict()
  54. else:
  55. params['buyer_id'] = self.buyer_id
  56. if self.buyer_pay_detail:
  57. if isinstance(self.buyer_pay_detail, list):
  58. for i in range(0, len(self.buyer_pay_detail)):
  59. element = self.buyer_pay_detail[i]
  60. if hasattr(element, 'to_alipay_dict'):
  61. self.buyer_pay_detail[i] = element.to_alipay_dict()
  62. if hasattr(self.buyer_pay_detail, 'to_alipay_dict'):
  63. params['buyer_pay_detail'] = self.buyer_pay_detail.to_alipay_dict()
  64. else:
  65. params['buyer_pay_detail'] = self.buyer_pay_detail
  66. if self.product_code:
  67. if hasattr(self.product_code, 'to_alipay_dict'):
  68. params['product_code'] = self.product_code.to_alipay_dict()
  69. else:
  70. params['product_code'] = self.product_code
  71. if self.total_amount:
  72. if hasattr(self.total_amount, 'to_alipay_dict'):
  73. params['total_amount'] = self.total_amount.to_alipay_dict()
  74. else:
  75. params['total_amount'] = self.total_amount
  76. if self.trade_no:
  77. if hasattr(self.trade_no, 'to_alipay_dict'):
  78. params['trade_no'] = self.trade_no.to_alipay_dict()
  79. else:
  80. params['trade_no'] = self.trade_no
  81. return params
  82. @staticmethod
  83. def from_alipay_dict(d):
  84. if not d:
  85. return None
  86. o = AlipayTradeOrderPayModel()
  87. if 'buyer_id' in d:
  88. o.buyer_id = d['buyer_id']
  89. if 'buyer_pay_detail' in d:
  90. o.buyer_pay_detail = d['buyer_pay_detail']
  91. if 'product_code' in d:
  92. o.product_code = d['product_code']
  93. if 'total_amount' in d:
  94. o.total_amount = d['total_amount']
  95. if 'trade_no' in d:
  96. o.trade_no = d['trade_no']
  97. return o