Subversion Repositories SmartDukaan

Rev

Rev 2293 | Rev 4141 | Go to most recent revision | Details | Compare with Previous | 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
2388 chandransh 28
    SET
29
    <if test="gatewayPaymentId != null">
30
      gatewayPaymentId = #{gatewayPaymentId},
31
    </if>
32
    <if test="sessionId != null">
33
      sessionId = #{sessionId},
34
    </if>
35
    <if test="gatewayTxnStatus != null">
36
      gatewayTxnStatus = #{gatewayTxnStatus},
37
    </if>
38
    <if test="description != null">
39
      description = #{description},
40
    </if>
41
    <if test="gatewayTxnId != null">
42
      gatewayTxnId = #{gatewayTxnId},
43
    </if>
44
    <if test="authCode != null">
45
      authCode = #{authCode},
46
    </if>
47
    <if test="referenceCode != null">
48
      referenceCode = #{referenceCode},
49
    </if> 
50
    <if test="gatewayTxnDate != null">
51
      gatewayTxnDate = #{gatewayTxnDate},
52
    </if>
53
    <if test="status != null">
54
      status = #{status},
55
    </if>
1946 chandransh 56
    errorCode = #{errorCode},
57
    successTimestamp = #{successTimestamp},
58
    errorTimestamp = #{errorTimestamp}
59
    WHERE id=#{id}
60
  </update>
61
 
62
  <sql id="selectAllPaymentFields">
63
    SELECT * FROM payment
64
  </sql>
65
 
66
  <select id="getPayment" parameterType="int" resultMap="paymentResult">
67
    <include refid="selectAllPaymentFields"/>
68
    WHERE id=#{id}
69
  </select>
70
 
71
  <select id="getPaymentForTxn" parameterType="int" resultMap="paymentResult">
72
    SELECT * FROM payment
73
    WHERE merchantTxnId=#{merchantTxnId}
2388 chandransh 74
    ORDER BY id DESC
75
    LIMIT 1
1946 chandransh 76
  </select>
77
 
2288 chandransh 78
  <sql id="getPaymentsWhereClause">
79
    <if test="fromTime != ''">
80
      initTimestamp &gt;= #{fromTime}
81
    </if>
2289 chandransh 82
    <if test="toTime != '' &amp;&amp; status == 0">
2288 chandransh 83
      AND initTimestamp &lt;= #{toTime}
84
    </if>
2289 chandransh 85
    <if test="toTime != '' &amp;&amp; status != 0">
2288 chandransh 86
      AND (errorTimestamp &lt;= #{toTime} OR successTimestamp &lt;= #{toTime})
87
    </if>
88
    <if test="status != -1">
89
      AND status=#{status}
90
    </if>
91
    <if test="gatewayId != 0">
92
      AND gatewayId = #{gatewayId}
93
    </if>
94
  </sql>
95
 
1946 chandransh 96
  <select id="getPayments" parameterType="map" resultMap="paymentResult">
97
    SELECT * FROM payment
98
    <where>
2288 chandransh 99
      <include refid="getPaymentsWhereClause"/>
1946 chandransh 100
    </where>
101
    ORDER BY id
102
  </select>
103
 
104
  <select id="getPaymentsForUser" parameterType="map" resultMap="paymentResult">
105
    SELECT * FROM payment
106
    <where>
2288 chandransh 107
      <include refid="getPaymentsWhereClause"/>
108
      AND userId=#{userId}
1946 chandransh 109
    </where>
110
    ORDER BY id
111
  </select>
112
 
113
  <select id="getMinMaxPaymentAmount" resultType="hashmap">
2293 chandransh 114
    SELECT MIN(AMOUNT) MIN, MAX(AMOUNT) MAX from payment WHERE status = 2
1946 chandransh 115
  </select>
116
 
117
  <select id="getAttributesForPayment" parameterType="int" resultType="paymentAttribute">
118
    SELECT * FROM paymentattribute where payment_id = #{id}
119
  </select>
120
</mapper>