Subversion Repositories SmartDukaan

Rev

Rev 2288 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1946 chandransh 1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
 
5
<mapper namespace="in.shop2020.payment.persistence.PaymentMapper">
6
 
7
  <resultMap type="payment" id="paymentResult">
8
    <id property="id" column="id"/>
9
    <collection property="attributes" javaType="ArrayList" column="id" ofType="paymentAttribute" select="getAttributesForPayment"/>
10
  </resultMap>
11
 
12
  <insert id="insertPayment" parameterType="payment" useGeneratedKeys="true" keyProperty="id">
13
    INSERT INTO payment
14
      (gatewayId, userId, merchantTxnId, amount, status, initTimestamp) 
15
    VALUES
16
      (#{gatewayId}, #{userId}, #{merchantTxnId}, #{amount}, #{status},  now())
17
  </insert>
18
 
19
  <insert id="insertPaymentAttribute" parameterType="map">
20
    INSERT INTO paymentattribute
21
      (payment_id, name, value)
22
    VALUES(#{paymentId}, #{name}, #{value})
23
    ON DUPLICATE KEY UPDATE value=values(value);
24
  </insert>
25
 
26
  <update id="updatePayment" parameterType="payment">
27
    UPDATE payment
28
    SET gatewayPaymentId = #{gatewayPaymentId},
29
    sessionId = #{sessionId},
30
    gatewayTxnStatus = #{gatewayTxnStatus},
31
    description = #{description},
32
    gatewayTxnId = #{gatewayTxnId},
33
    authCode = #{authCode},
34
    referenceCode = #{referenceCode},
35
    errorCode = #{errorCode},
36
    status = #{status},
37
    gatewayTxnDate = #{gatewayTxnDate},
38
    successTimestamp = #{successTimestamp},
39
    errorTimestamp = #{errorTimestamp}
40
    WHERE id=#{id}
41
  </update>
42
 
43
  <sql id="selectAllPaymentFields">
44
    SELECT * FROM payment
45
  </sql>
46
 
47
  <select id="getPayment" parameterType="int" resultMap="paymentResult">
48
    <include refid="selectAllPaymentFields"/>
49
    WHERE id=#{id}
50
  </select>
51
 
52
  <select id="getPaymentForTxn" parameterType="int" resultMap="paymentResult">
53
    SELECT * FROM payment
54
    WHERE merchantTxnId=#{merchantTxnId}
55
  </select>
56
 
57
  <select id="getPayments" parameterType="map" resultMap="paymentResult">
58
    SELECT * FROM payment
59
    <where>
60
      <if test="fromTime != ''">
61
        initTimestamp &gt;= #{fromTime}
62
      </if>
63
      <if test="toTime != ''">
64
        AND initTimestamp &lt;= #{toTime}
65
      </if>
66
      <if test="status != -1">
67
        AND status=#{status}
68
      </if>
69
      <if test="gatewayId != -1">
70
        AND gatewayId = #{gatewayId}
71
      </if>
72
    </where>
73
    ORDER BY id
74
  </select>
75
 
76
  <select id="getPaymentsForUser" parameterType="map" resultMap="paymentResult">
77
    SELECT * FROM payment
78
    <where>
79
      userId=#{userId}
80
      <if test="fromTime != ''">
81
        AND initTimestamp &gt;= #{fromTime}
82
      </if>
83
      <if test="toTime != ''">
84
        AND initTimestamp &lt;= #{toTime}
85
      </if>
86
      <if test="status != -1">
87
        AND status=#{status}
88
      </if>
89
      <if test="gatewayId != -1">
90
        AND gatewayId = #{gatewayId}
91
      </if>
92
    </where>
93
    ORDER BY id
94
  </select>
95
 
96
  <select id="getMinMaxPaymentAmount" resultType="hashmap">
97
    SELECT MIN(AMOUNT) MIN, MAX(AMOUNT) MAX from payment
98
  </select>
99
 
100
  <select id="getAttributesForPayment" parameterType="int" resultType="paymentAttribute">
101
    SELECT * FROM paymentattribute where payment_id = #{id}
102
  </select>
103
</mapper>