Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
fix bug with signin and pulling saved payment, fix schedule error bug…
Browse files Browse the repository at this point in the history
…, add GA tracking
  • Loading branch information
James Baxley committed Dec 2, 2016
1 parent 3dc79a3 commit 80580e7
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Meteor.startup(() => {

ga("create", Meteor.settings.public.ga, "auto");
ga("send", "pageview");
ga("require", "ecommerce");
}

if (Meteor.settings.public.hotjar) {
Expand Down
4 changes: 4 additions & 0 deletions imports/blocks/add-to-cart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class CartContainer extends Component {
props: ICartContainer;
state: ICartContainerState;

static defaultProps = {
accounts: [],
}

state = { subfunds: [] }

componentWillMount() {
Expand Down
17 changes: 15 additions & 2 deletions imports/blocks/checkout-buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const SAVED_ACCTS_QUERY = gql`
// XXX remove cache: false when heighliner caching is tested
export const withSavedPayments = graphql(SAVED_ACCTS_QUERY, {
name: "savedPayments",
// skip: (ownProps) => !ownProps.authorized,
options: () => ({
variables: {
cache: false,
Expand Down Expand Up @@ -80,12 +81,17 @@ type ICheckoutButtons = {
text: string,
theme: string,
value: string,
refetch: Function,
};

export class CheckoutButton extends Component {

props: ICheckoutButtons;

static defaultProps = {
savedPayments: {},
}

state = {
paymentDetails: false,
}
Expand All @@ -103,7 +109,6 @@ export class CheckoutButton extends Component {
this.props.dispatch(giveActions.setTransactionType("default"));

if (this.props.savedPayments.savedPayments) {
// const details = this.props.savedAccount[Object.keys(this.props.savedAccount)[0]]
const details = this.getAccount();
this.props.dispatch(giveActions.setAccount(details));
}
Expand Down Expand Up @@ -165,7 +170,15 @@ export class CheckoutButton extends Component {

renderAfterLogin = () => {
if (this.props.disabled) return this.props.dispatch(modal.hide());
this.props.dispatch(modal.render(Give));
// get the payment details before finishing payment
this.props.savedPayments.refetch()
.then(({ data }) => {
if (data.savedPayments && data.savedPayments.length) {
const details = sortBy(data.savedPayments, "date")[data.savedPayments.length - 1]
this.props.dispatch(giveActions.setAccount(details));
}
this.props.dispatch(modal.render(Give));
});
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports[`successful charge using a saved payment ends after a normal charge 1`] = `
Array [
Array [
"ecommerce:addTransaction",
Object {
"affiliation": "NewSpring Church",
"id": "TOKEN",
"revenue": "0",
},
],
Array [
"ecommerce:send",
],
]
`;
5 changes: 5 additions & 0 deletions imports/store/give/saga/__tests__/chargeTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe("successful charge saved payment and schedules", () => {

});

window.ga = jest.fn();
describe("successful charge using a saved payment", () => {
const it = sagaHelper(chargeTransaction({ state: "submit" }));
const initalState = {
Expand Down Expand Up @@ -193,10 +194,14 @@ describe("successful charge using a saved payment", () => {
});

it("puts a success state", result => {
ga.mockClear();
expect(result).toEqual(put(actions.setState("success")));
});

it("ends after a normal charge", result => {
expect(window.ga.mock.calls).toMatchSnapshot();
expect(window.ga).toHaveBeenCalledTimes(2)
delete window.ga;
expect(result).toBeUndefined();
});

Expand Down
2 changes: 1 addition & 1 deletion imports/store/give/saga/__tests__/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ describe("failure in charge", () => {

it("finally returns an object with faling status", ({ success, validationError }) => {
expect(success).toBe(false);
expect(validationError.message).toBe("SAMPLE ERROR");
expect(validationError).toBe("SAMPLE ERROR");
});
});
22 changes: 22 additions & 0 deletions imports/store/give/saga/chargeTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ export default function* chargeTransaction({ state }) {
// remove loading state
yield put(actions.setState("success"));

if (typeof ga !== "undefined") {
const txns = {
id: `${give.url.split("/").pop()}`,
affiliation: "NewSpring Church",
revenue: `${give.total}`,
};
ga("ecommerce:addTransaction", txns);

if (Object.keys(give.transactions)) {
// eslint-disable-next-line
for (const item in give.transactions) {
const itemData = {
id: item,
name: give.transactions[item].label,
price: `${give.transactions[item].value}`,
};
ga("ecommerce:addItem", itemData);
}
}
ga("ecommerce:send");
}

// if we activated an inactive schedule, remove it
if (give.scheduleToRecover && give.recoverableSchedules[give.scheduleToRecover]) {
yield put(actions.deleteSchedule(give.scheduleToRecover));
Expand Down
2 changes: 1 addition & 1 deletion imports/store/give/saga/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function* validate() {
if (result && result.data) {
const { response } = result.data;
if (response.error) {
validationError = new Error(response.error);
validationError = response.error;
success = false;
}
}
Expand Down

0 comments on commit 80580e7

Please sign in to comment.