Skip to content

Commit 1449d1a

Browse files
Format updates and can now request more checkouts
Added a button that allows the user to request more checkouts and adds them directly into the table. Each fetch will get 50 entires.
1 parent 9479237 commit 1449d1a

File tree

5 files changed

+118
-36
lines changed

5 files changed

+118
-36
lines changed

actions/checkouts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function invalidateCheckout(email, account_id = null, checkout_id=null) {
2424
}
2525
}
2626

27-
function requestCheckout(email, account_id = null, checkout_id = null) {
27+
function requestCheckout(email, account_id = null, checkout_id = null, start = null, stop = null) {
2828
return {
2929
type: REQUEST,
3030
email:email,
@@ -80,11 +80,11 @@ function requestRefund(email, checkout_id, amount=null, refund_reason) {
8080
}
8181
}
8282

83-
function fetchCheckout(email, account_id = null, checkout_id = null) {
83+
function fetchCheckout(email, account_id = null, checkout_id = null, start = null) {
8484
return dispatch => {
8585
dispatch(requestCheckout(email, account_id, checkout_id))
8686

87-
return $.post("/checkout", {"email":email, "checkout_id":checkout_id, "account_id":account_id})
87+
return $.post("/checkout", {"email":email, "checkout_id":checkout_id, "account_id":account_id, "start":start})
8888
.fail(function(data){
8989
console.log("ERROR: ", data);
9090
var error_data = JSON.parse(data.responseText);
@@ -97,7 +97,7 @@ function fetchCheckout(email, account_id = null, checkout_id = null) {
9797
}
9898

9999
function shouldFetchCheckout(state, account_id) {
100-
if (state.wepay_account && state.wepay_account.searchedAccount.account_id != null) {
100+
if (state.wepay_account && state.wepay_account.searchedAccount.account_id != null && !state.wepay_checkout.checkout.isFetching) {
101101
return true;
102102
}
103103
else if(state.wepay_user.isFetching){
@@ -106,10 +106,10 @@ function shouldFetchCheckout(state, account_id) {
106106
return false;
107107
}
108108

109-
export function fetchCheckoutIfNeeded(email, account_id=null, checkout_id=null) {
109+
export function fetchCheckoutIfNeeded(email, account_id=null, checkout_id=null, start = null) {
110110
return (dispatch, getState) => {
111111
if (shouldFetchCheckout(getState())) {
112-
return dispatch(fetchCheckout(email, account_id, checkout_id))
112+
return dispatch(fetchCheckout(email, account_id, checkout_id, start))
113113
}
114114
}
115115
}

components/Checkouts.js

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { PropTypes } from 'react'
2-
import {Grid, Label, FormGroup, FormControl, Row, Col, ControlLabel, Table, Button, Modal} from "react-bootstrap"
2+
import {Grid, Form, Label, FormGroup, FormControl, Row, Col, ControlLabel, Table, Button, Modal} from "react-bootstrap"
33
import { connect } from 'react-redux'
44
import {BootstrapTable} from "react-bootstrap-table"
55

6-
import {fetchRefundIfNeeded, clearRefund} from "../actions/checkouts"
6+
import {fetchRefundIfNeeded, clearRefund, fetchCheckoutIfNeeded} from "../actions/checkouts"
77

88
import Base from "./Base"
99

@@ -19,7 +19,6 @@ var Checkouts = React.createClass({
1919
}
2020
},
2121
openModal: function(event) {
22-
console.log("OPENING MODAL", event.target.id);
2322
this.setState({showModal:true, refund:{selectedCheckoutId: event.target.id}});
2423
},
2524
closeModal: function() {
@@ -46,7 +45,6 @@ var Checkouts = React.createClass({
4645
if (this.props.successful_refund) {
4746
successful_refund = (<h3><Label bsStyle="success">Refund completed!</Label></h3>);
4847
}
49-
console.log(successful_refund);
5048
return (
5149
<div>
5250
<Modal show = {this.state.showModal} onHide = {this.closeModal}>
@@ -55,48 +53,101 @@ var Checkouts = React.createClass({
5553
</Modal.Header>
5654
<Modal.Body>
5755
<p><strong>Max Refundable Amount:</strong> ${maxRefundableAmount}</p>
58-
<form onSubmit={this.refundCheckout}>
56+
<Form horizontal onSubmit={this.refundCheckout}>
5957
<FormGroup>
60-
<ControlLabel>Refund Amount</ControlLabel>
61-
<FormControl
62-
type="number"
63-
id="refundAmount"
64-
max={maxRefundableAmount}
65-
required
66-
/>
58+
<Col lg={6} ms={12}>
59+
<ControlLabel>Refund Amount</ControlLabel>
60+
<FormControl
61+
type="number"
62+
id="refundAmount"
63+
step="0.01"
64+
max={maxRefundableAmount}
65+
ref = "refundAmount"
66+
onChange = {this.handleAmountChange}
67+
required
68+
/>
69+
</Col>
70+
<Col lg={6} ms={12}>
71+
<ControlLabel>Refund Percentage</ControlLabel>
72+
<FormControl
73+
type="number"
74+
id="refundPercentage"
75+
step="0.01"
76+
max="100"
77+
onChange={this.handlePercentChange}
78+
/>
79+
</Col>
6780
</FormGroup>
6881
<FormGroup>
69-
<ControlLabel>Refund Reason</ControlLabel>
70-
<FormControl
71-
type="text"
72-
id="refundReason"
73-
required/>
82+
<Col lg={12}>
83+
<ControlLabel>Refund Reason</ControlLabel>
84+
<FormControl
85+
type="text"
86+
id="refundReason"
87+
required/>
88+
</Col>
7489
</FormGroup>
75-
{successful_refund}
76-
<Button type="submit" bsStyle="success" value="Submit Refund" disabled={this.props.submitted_refund}>Submit Refund</Button>
77-
</form>
90+
<FormGroup>
91+
<Col lg={12}>
92+
{successful_refund}
93+
</Col>
94+
</FormGroup>
95+
<FormGroup>
96+
<Col lg={12}>
97+
<Button type="submit" bsStyle="success" value="Submit Refund" disabled={this.props.submitted_refund}>Submit Refund</Button>
98+
</Col>
99+
</FormGroup>
100+
</Form>
78101
</Modal.Body>
79102
</Modal>
80103
</div>
81104
);
82105
},
83106
handleAmountChange: function(event) {
84-
var current = this.state.refund;
85-
current.refundAmount = event.target.value;
86-
this.setState({refund: current})
107+
var currentPercent = $("#refundPercentage");
108+
var refundAmount = event.target.value;
109+
var maxRefundableAmount = $("#refundAmount").prop("max");
110+
currentPercent.val(((refundAmount*100)/maxRefundableAmount).toFixed(2));
111+
112+
},
113+
handlePercentChange: function(event) {
114+
var currentAmount = $("#refundAmount");
115+
var currentPercent = event.target.value;
116+
var maxRefundableAmount = $("#refundAmount").prop("max");
117+
118+
// change the refund amount based on the percent value that the user has entered
119+
// this is designed to make the refund easier. If their policy is to refund half, this takes away the guess work
120+
currentAmount.val((maxRefundableAmount * (currentPercent/100.0)).toFixed(2));
121+
87122
},
88123
handleReasonChange: function(event) {
89124
var current = this.state.refund;
90125
current.refundReason = event.target.value;
91126
this.setState({refund: current})
92127
},
128+
fetchMoreCheckouts: function(event) {
129+
console.log("Fetching more checkouts for: ", this.props.email, this.props.account_id);
130+
var start = this.props.checkoutInfo.length;
131+
this.props.dispatch(fetchCheckoutIfNeeded(this.props.email, this.props.account_id, null, start));
132+
},
93133
refundCheckout: function(e) {
94134
e.preventDefault();
95135
console.log("Performing refund for: ", this.state.refund.selectedCheckoutId);
136+
96137
var checkout_id = this.state.refund.selectedCheckoutId;
97138
var refundAmount = $("#refundAmount").val();
98139
var refundReason = $("#refundReason").val();
140+
var maxRefundableAmount = $("#refundAmount").prop("max");
141+
142+
console.log(refundAmount, maxRefundableAmount);
143+
144+
if (refundAmount - maxRefundableAmount == 0) {
145+
console.log("Full refund!");
146+
refundAmount = null;
147+
}
99148
var current = this.state.refund;
149+
current['refundAmount'] = refundAmount;
150+
current['refundReason'] = refundReason;
100151
this.setState({refund:current})
101152

102153
this.props.dispatch(fetchRefundIfNeeded(this.props.email, checkout_id, refundAmount, refundReason));
@@ -114,7 +165,7 @@ var Checkouts = React.createClass({
114165
var refundString = (<p><strong>Refunded</strong>: ${cell}<br></br>{row.refund_refund_reason}</p>);
115166
var refundButton = (<Button bsStyle="primary" bsSize="small" id={row.checkout_id} onClick={this.openModal}>Refund</Button>)
116167
if (cell > 0) {
117-
if (cell == row.amount) {
168+
if (cell >= row.amount) {
118169
return (<div>{refundString}</div>)
119170
}
120171
else {
@@ -183,7 +234,12 @@ var Checkouts = React.createClass({
183234
dataField = "amount"
184235
>
185236
Amount
186-
</TableHeaderColumn>
237+
</TableHeaderColumn>
238+
<TableHeaderColumn
239+
dataField="gross"
240+
>
241+
Gross Amount
242+
</TableHeaderColumn>
187243
<TableHeaderColumn
188244
dataField = "payer_email"
189245
>
@@ -202,6 +258,15 @@ var Checkouts = React.createClass({
202258
</TableHeaderColumn>
203259
</BootstrapTable>
204260
</Row>
261+
<Row>
262+
<div className="pull-right">
263+
<Button
264+
id="fetchMoreCheckouts"
265+
onClick = {this.fetchMoreCheckouts}
266+
bsStyle="primary"
267+
>Get More Checkouts</Button>
268+
</div>
269+
</Row>
205270
{this.buildModal()}
206271
</div>
207272
);
@@ -213,6 +278,7 @@ const mapStateToProps = (state) => {
213278
return {
214279
checkoutInfo:state.wepay_checkout.checkout.checkoutInfo,
215280
email: state.wepay_user.searchedUser,
281+
account_id: state.wepay_account.searchedAccount.account_id,
216282
error: state.errors.info,
217283
submitted_refund: state.wepay_checkout.checkout.submitted_refund,
218284
successful_refund: state.wepay_checkout.checkout.successful_refund,

components/Withdrawals.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var Withdrawals= React.createClass({
2626
}
2727
return array;
2828
},
29+
formatBank: function(cell, row) {
30+
return row.bank_data_bank_name + " XXXXXX" + cell;
31+
},
2932
render: function() {
3033
var withdrawals = this.props.withdrawalInfo;
3134
console.log("WITHDRAWALS: ", withdrawals);
@@ -64,8 +67,9 @@ var Withdrawals= React.createClass({
6467
</TableHeaderColumn>
6568
<TableHeaderColumn
6669
dataField="bank_data_account_last_four"
70+
dataFormat={this.formatBank}
6771
>
68-
Account Last Four
72+
Bank
6973
</TableHeaderColumn>
7074

7175
</BootstrapTable>

reducers/checkouts.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ function updateCheckout(state, action) {
3333
break;
3434
}
3535
}
36+
state.isFeteching = false;
3637
return state
3738
}
3839

40+
function appendCheckouts(state, action){
41+
if (state.checkoutInfo.length > 0) {
42+
43+
}
44+
}
45+
3946

4047

4148
function checkout_base(state = {
@@ -62,7 +69,7 @@ function checkout_base(state = {
6269
return Object.assign({}, state, {
6370
isFetching: false,
6471
didInvalidate: false,
65-
checkoutInfo: action.checkout,
72+
checkoutInfo: (state.checkoutInfo ? state.checkoutInfo.concat(action.checkout): action.checkout),
6673
lastUpdated: action.receivedAt
6774
})
6875
case REFUND:

server.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ app.use('/static', express.static('static'));
2424
function sendResponse(package, res) {
2525
res.setHeader('Content-Type', 'application/json');
2626
if ("error_code" in package) {
27-
console.log("Sending error!");
28-
res.status(500).send(JSON.stringify({"error_code":500, "error_description":"wepay call died. check server logs for more details.", "error_message":package.error_description}));
27+
var error_package = {"error_code":500, "error_description":"wepay call died. check server logs for more details.", "error_message":package.error_description}
28+
console.log("Sending error!\t", error_package);
29+
res.status(500).send(JSON.stringify(error_package));
2930
}
3031
else {
3132
res.send(JSON.stringify(package));
@@ -148,7 +149,11 @@ app.post("/checkout", function(req, res) {
148149
getDataWithPackage(req, res, "/checkout", package);
149150
}
150151
else {
151-
getDataWithAccountId(req, res, "/checkout/find");
152+
var package = {"account_id": req.body.account_id};
153+
if (req.body.start && req.body.start != '') {
154+
package.start = req.body.start;
155+
}
156+
getDataWithPackage(req, res, "/checkout/find", package);
152157
}
153158
})
154159

0 commit comments

Comments
 (0)