예제 #1
0
    def test_place_order(self):
        class AlipayApisMock(object):
            test_case = self

            def __init__(self, app_id, private_key, alipay_public_key):
                assert app_id == dynasettings.ALIPAY_APP_ID
                assert private_key == dynasettings.ALIPAY_APP_PRIVATE_KEY
                assert alipay_public_key == dynasettings.ALIPAY_PUBLIC_KEY

            def place_order(self, notify_url, order_title,
                            payment_serial_number, total_amount, buyer_id):
                assert notify_url == 'http://test.com'
                assert order_title == self.test_case.merchant.name
                assert len(payment_serial_number) == 32
                assert total_amount == 1900
                assert buyer_id == '1234567890'

                return {
                    'code': '10000',
                    'msg': 'Success',
                    'out_trade_no': payment_serial_number,
                    'trade_no': '2018110522001483870500447579'
                }

        AlipayUseCases.api_cls = AlipayApisMock
        alipay_usecases = AlipayUseCases()
        result = alipay_usecases.place_order(self.client, self.merchant,
                                             self.coupon, 2000,
                                             'http://test.com')
        assert result['trade_no'] == '2018110522001483870500447579'

        new_payment = Payment.objects.all().order_by('-datetime')[0]

        assert new_payment
        assert len(new_payment.serial_number) == 32
        assert len(new_payment.transactions.all()) == 0
        assert (timezone.now() - new_payment.datetime) < timedelta(seconds=30)
        assert new_payment.pay_channel == PAY_CHANNELS.ALIPAY
        assert new_payment.merchant_id == self.merchant.id
        assert new_payment.status == PAYMENT_STATUS.UNPAID
        assert new_payment.client_id == self.client.id
        assert new_payment.order_price == 2000
        assert new_payment.coupon_id == self.coupon.id
        assert new_payment.platform_share == round(1900 * PLATFORM_SHARE_RATE)
        assert new_payment.inviter_share == round(1900 * INVITER_SHARE_RATE)
        assert new_payment.originator_share == round(1900 *
                                                     ORIGINATOR_SHARE_RATE)
        assert new_payment.note is None
예제 #2
0
    def test_place_order_without_coupon(self):
        class AlipayApisMock(object):
            test_case = self

            def __init__(self, app_id, private_key, alipay_public_key):
                assert app_id == dynasettings.ALIPAY_APP_ID
                assert private_key == dynasettings.ALIPAY_APP_PRIVATE_KEY
                assert alipay_public_key == dynasettings.ALIPAY_PUBLIC_KEY

            def place_order(self, notify_url, order_title,
                            payment_serial_number, total_amount, buyer_id):
                assert notify_url == 'http://test.com'
                assert order_title == self.test_case.merchant.name
                assert len(payment_serial_number) == 32
                assert total_amount == 2000
                assert buyer_id == '1234567890'

                return 'place_order_success'

        AlipayUseCases.api_cls = AlipayApisMock
        alipay_usecases = AlipayUseCases()
        result = alipay_usecases.place_order(self.client, self.merchant, None,
                                             2000, 'http://test.com')
        assert result == 'place_order_success'

        new_payment = Payment.objects.all().order_by('-datetime')[0]

        assert new_payment
        assert len(new_payment.serial_number) == 32
        assert len(new_payment.transactions.all()) == 0
        assert (timezone.now() - new_payment.datetime) < timedelta(seconds=30)
        assert new_payment.pay_channel == PAY_CHANNELS.ALIPAY
        assert new_payment.merchant_id == self.merchant.id
        assert new_payment.status == PAYMENT_STATUS.UNPAID
        assert new_payment.client_id == self.client.id
        assert new_payment.order_price == 2000
        assert new_payment.coupon is None
        assert new_payment.platform_share == 0
        assert new_payment.inviter_share == 0
        assert new_payment.originator_share == 0
        assert new_payment.note is None