require 'test_helper' class Alipay::ServiceTest < Minitest::Test def test_generate_create_partner_trade_by_buyer_url options = { out_trade_no: '1', subject: 'test', logistics_type: 'POST', logistics_fee: '0', logistics_payment: 'SELLER_PAY', price: '0.01', quantity: 1 } assert_equal 'https://mapi.alipay.com/gateway.do?service=create_partner_trade_by_buyer&_input_charset=utf-8&partner=1000000000000000&seller_id=1000000000000000&payment_type=1&out_trade_no=1&subject=test&logistics_type=POST&logistics_fee=0&logistics_payment=SELLER_PAY&price=0.01&quantity=1&sign_type=MD5&sign=b5d30863b44acd8514a49b0320fb2aa2', Alipay::Service.create_partner_trade_by_buyer_url(options) end def test_generate_trade_create_by_buyer_url options = { out_trade_no: '1', subject: 'test', logistics_type: 'POST', logistics_fee: '0', logistics_payment: 'SELLER_PAY', price: '0.01', quantity: 1 } assert_equal 'https://mapi.alipay.com/gateway.do?service=trade_create_by_buyer&_input_charset=utf-8&partner=1000000000000000&seller_id=1000000000000000&payment_type=1&out_trade_no=1&subject=test&logistics_type=POST&logistics_fee=0&logistics_payment=SELLER_PAY&price=0.01&quantity=1&sign_type=MD5&sign=2d296368fea70a127da939558c970bab', Alipay::Service.trade_create_by_buyer_url(options) end def test_generate_create_direct_pay_by_user_url options = { out_trade_no: '1', subject: 'test', price: '0.01', quantity: 1 } assert_equal 'https://mapi.alipay.com/gateway.do?service=create_direct_pay_by_user&_input_charset=utf-8&partner=1000000000000000&seller_id=1000000000000000&payment_type=1&out_trade_no=1&subject=test&price=0.01&quantity=1&sign_type=MD5&sign=682ad02280fca7d4c0fd22678fdddeef', Alipay::Service.create_direct_pay_by_user_url(options) end def test_generate_create_direct_pay_by_user_wap_url options = { out_trade_no: '1', subject: 'test', total_fee: '0.01' } assert_equal 'https://mapi.alipay.com/gateway.do?service=alipay.wap.create.direct.pay.by.user&_input_charset=utf-8&partner=1000000000000000&seller_id=1000000000000000&payment_type=1&out_trade_no=1&subject=test&total_fee=0.01&sign_type=MD5&sign=6530de6e3cba153cd4ca7edc48b91f96', Alipay::Service.create_direct_pay_by_user_wap_url(options) end def test_refund_fastpay_by_platform_pwd_url data = [{ trade_no: '1', amount: '0.01', reason: 'test' }] options = { batch_no: '123456789', data: data, notify_url: '/some_url', refund_date: '2015-01-01 00:00:00' } assert_equal 'https://mapi.alipay.com/gateway.do?service=refund_fastpay_by_platform_pwd&_input_charset=utf-8&partner=1000000000000000&seller_user_id=1000000000000000&refund_date=2015-01-01+00%3A00%3A00&batch_num=1&detail_data=1%5E0.01%5Etest&batch_no=123456789¬ify_url=%2Fsome_url&sign_type=MD5&sign=def57a58e1ac21f70c45e41bd3697368', Alipay::Service.refund_fastpay_by_platform_pwd_url(options) end def test_forex_refund_url options = { out_return_no: '1', out_trade_no: '12345678980', return_amount: '0.01', currency: 'USD', reason: 'reason', gmt_return: '20150101000000' } assert_equal 'https://mapi.alipay.com/gateway.do?service=forex_refund&partner=1000000000000000&_input_charset=utf-8&gmt_return=20150101000000&out_return_no=1&out_trade_no=12345678980&return_amount=0.01¤cy=USD&reason=reason&sign_type=MD5&sign=c9681fff5505fe993d1b2b8141308d0d', Alipay::Service.forex_refund_url(options) end def test_generate_create_forex_trade_url options = { notify_url: 'https://example.com/notify', subject: 'test', out_trade_no: '1', currency: 'EUR', total_fee: '0.01', } assert_equal 'https://mapi.alipay.com/gateway.do?service=create_forex_trade&_input_charset=utf-8&partner=1000000000000000¬ify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=test&out_trade_no=1¤cy=EUR&total_fee=0.01&sign_type=MD5&sign=f24fd4d76acabf860263a40805138380', Alipay::Service.create_forex_trade_url(options) end def test_close_trade response_body = <<-EOF T EOF FakeWeb.register_uri( :get, %r|https://mapi\.alipay\.com/gateway\.do.*|, body: response_body ) assert_equal response_body, Alipay::Service.close_trade( out_order_no: '1' ) end def test_single_trade_query response_body = <<-EOF T 20150123123123 utf-8 single_trade_query PARTNER DAEMON_CONFIRM_CLOSE buyer@example.com BUYER_ID 0.00 0 2015-01-20 02:37:00 2015-01-20 02:17:00 2015-01-20 02:37:00 F B 1 1 640.00 1 seller@example.com SELLER_ID ORDER SUBJECT 0.00 0.00 640.00 TRADE_NO TRADE_CLOSED F SIGN MD5 EOF FakeWeb.register_uri( :get, %r|https://mapi\.alipay\.com/gateway\.do.*|, body: response_body ) assert_equal response_body, Alipay::Service.single_trade_query( out_trade_no: '1' ) end def test_should_send_goods_confirm_by_platform body = <<-EOF T EOF FakeWeb.register_uri( :get, %r|https://mapi\.alipay\.com/gateway\.do.*|, body: body ) assert_equal body, Alipay::Service.send_goods_confirm_by_platform( trade_no: 'trade_no', logistics_name: 'example.com', transport_type: 'DIRECT' ) end end