Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Stripe Connect Capture charge #2824

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
425ff5d
Capture just the records for a particular shop
brent-hoover Sep 8, 2017
2da0fb4
if refund results are empty do nothing
brent-hoover Sep 8, 2017
5529103
Catch and log errors with refunds
brent-hoover Sep 8, 2017
fbca2c5
Return all orders where the users shopId is attached to an item
brent-hoover Sep 11, 2017
f9d5b2b
Return all orders where the users shopId is attached to an item
brent-hoover Sep 11, 2017
9635ce1
Merge branch 'marketplace' into brent-fix-issue-2765
brent-hoover Sep 11, 2017
cb81e27
Remove validated-method mess I created. Use plain functions
brent-hoover Sep 11, 2017
c05eec4
Fix stripe tests
brent-hoover Sep 11, 2017
3743aa7
Fix fixtures
brent-hoover Sep 11, 2017
c9436bd
Correctly store paymentPackageId and then use that to get right key
brent-hoover Sep 11, 2017
8e0ad77
Approve by shopId
brent-hoover Sep 11, 2017
9800351
Don't rewrite values when approving order
brent-hoover Sep 11, 2017
12f6d59
Use an aggregate function to filter orders
brent-hoover Sep 12, 2017
089c08e
Create a reactive-aggregate
brent-hoover Sep 12, 2017
47a747b
Add JSDoc and check
brent-hoover Sep 12, 2017
cd10fed
Fix Stripe tests
brent-hoover Sep 12, 2017
403a7a3
Don't hardcode shopId
brent-hoover Sep 12, 2017
961f946
Fix tests
brent-hoover Sep 12, 2017
b04bd8c
pass in orderCount to orderTable
brent-hoover Sep 12, 2017
3c1fdb4
pass in orderCount to orderTable
brent-hoover Sep 12, 2017
94f5096
Merge branch 'marketplace' into brent-fix-issue-2765
brent-hoover Sep 12, 2017
1506fb6
Merge branch 'marketplace' into brent-fix-issue-2765
spencern Sep 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OrderDashboard extends Component {
handleSelect: PropTypes.func,
isLoading: PropTypes.object,
multipleSelect: PropTypes.bool,
orderCount: PropTypes.number,
orders: PropTypes.array,
query: PropTypes.object,
renderFlowList: PropTypes.bool,
Expand Down Expand Up @@ -89,6 +90,7 @@ class OrderDashboard extends Component {
<div>
<OrderTable
orders={this.props.orders}
orderCount={this.props.orderCount}
query={this.state.query}
selectedItems={this.props.selectedItems}
handleSelect={this.props.handleSelect}
Expand Down
3 changes: 2 additions & 1 deletion imports/plugins/core/orders/client/components/orderTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OrderTable extends Component {
isLoading: PropTypes.object,
isOpen: PropTypes.bool,
multipleSelect: PropTypes.bool,
orderCount: PropTypes.number,
orders: PropTypes.array,
query: PropTypes.object,
renderFlowList: PropTypes.bool,
Expand Down Expand Up @@ -337,7 +338,7 @@ class OrderTable extends Component {
}
publication="CustomPaginatedOrders"
collection={Orders}
matchingResultsCount="order-count"
matchingResultsCount={this.props.orderCount.toString()}
query={this.props.query}
columnMetadata={customColumnMetadata}
externalLoadingComponent={Loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const OrderHelper = {
class OrderDashboardContainer extends Component {
static propTypes = {
handleMenuClick: PropTypes.func,
orderCount: PropTypes.number,
orders: PropTypes.array
}

Expand Down Expand Up @@ -737,6 +738,7 @@ class OrderDashboardContainer extends Component {
return (
<OrderDashboard
handleSelect={this.handleSelect}
orderCount={this.props.orderCount}
orders={this.state.orders}
query={this.state.query}
filter={this.state.filter}
Expand Down Expand Up @@ -765,9 +767,10 @@ const composer = (props, onData) => {

if (mediaSubscription.ready() && ordersSubscription.ready()) {
const orders = Orders.find().fetch();

const orderCount = Orders.find().count();
onData(null, {
orders
orders,
orderCount
});
}
};
Expand Down
42 changes: 25 additions & 17 deletions imports/plugins/included/payments-stripe/server/methods/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ function stripeCaptureCharge(paymentMethod) {
amount: formatForStripe(paymentMethod.amount)
};

const stripePackage = Packages.findOne(paymentMethod.paymentPackageId);
const stripeKey = stripePackage.settings.api_key || stripePackage.settings.connectAuth.access_token;

try {
const captureResult = StripeApi.methods.captureCharge.call({
const captureResult = StripeApi.methods.captureCharge({
transactionId: paymentMethod.transactionId,
captureDetails: captureDetails
captureDetails: captureDetails,
apiKey: stripeKey
});
if (captureResult.status === "succeeded") {
result = {
Expand Down Expand Up @@ -120,10 +124,7 @@ function buildPaymentMethods(options) {

const shopIds = Object.keys(transactionsByShopId);
const storedCard = cardData.type.charAt(0).toUpperCase() + cardData.type.slice(1) + " " + cardData.number.slice(-4);
const packageData = Packages.findOne({
name: "reaction-stripe",
shopId: Reaction.getPrimaryShopId()
});


const paymentMethods = [];

Expand All @@ -140,6 +141,11 @@ function buildPaymentMethods(options) {
};
});

const packageData = Packages.findOne({
name: "reaction-stripe",
shopId: shopId
});

const paymentMethod = {
processor: "Stripe",
storedCard: storedCard,
Expand Down Expand Up @@ -350,7 +356,7 @@ export const methods = {
*/
"stripe/payment/capture": function (paymentMethod) {
check(paymentMethod, Reaction.Schemas.PaymentMethod);
// let result;

const captureDetails = {
amount: formatForStripe(paymentMethod.amount)
};
Expand Down Expand Up @@ -388,7 +394,7 @@ export const methods = {

let result;
try {
const refundResult = StripeApi.methods.createRefund.call({ refundDetails });
const refundResult = StripeApi.methods.createRefund({ refundDetails });
Logger.debug(refundResult);
if (refundResult && refundResult.object === "refund") {
result = {
Expand Down Expand Up @@ -423,16 +429,18 @@ export const methods = {
check(paymentMethod, Reaction.Schemas.PaymentMethod);
let result;
try {
const refunds = StripeApi.methods.listRefunds.call({ transactionId: paymentMethod.transactionId });
const refunds = StripeApi.methods.listRefunds({ transactionId: paymentMethod.transactionId });
result = [];
for (const refund of refunds.data) {
result.push({
type: refund.object,
amount: refund.amount / 100,
created: refund.created * 1000,
currency: refund.currency,
raw: refund
});
if (refunds) {
for (const refund of refunds.data) {
result.push({
type: refund.object,
amount: refund.amount / 100,
created: refund.created * 1000,
currency: refund.currency,
raw: refund
});
}
}
} catch (error) {
Logger.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Meteor } from "meteor/meteor";
import { expect } from "meteor/practicalmeteor:chai";
import { sinon } from "meteor/practicalmeteor:sinon";
import { Packages } from "/lib/collections";
import { StripeApi } from "./stripeapi";

const stripeCaptureResult = {
Expand Down Expand Up @@ -78,10 +79,12 @@ describe("stripe/payment/capture", function () {
});

it("should call StripeApi.methods.captureCharge with the proper parameters and return saved = true", function (done) {
const stripePackage = Packages.findOne({ name: "reaction-stripe" });
const apiKey = stripePackage.settings.api_key;
const paymentMethod = {
processor: "Stripe",
storedCard: "Visa 4242",
paymentPackageId: "vrXutd72c2m7Lenqw",
paymentPackageId: stripePackage._id,
paymentSettingsKey: "reaction-stripe",
method: "credit",
transactionId: "ch_17hZ4wBXXkbZQs3xL5JhlSgS",
Expand All @@ -90,10 +93,9 @@ describe("stripe/payment/capture", function () {
mode: "capture",
createdAt: new Date()
};
sandbox.stub(StripeApi.methods.captureCharge, "call", function () {
sandbox.stub(StripeApi.methods, "captureCharge", function () {
return stripeCaptureResult;
});
// spyOn(StripeApi.methods.captureCharge, "call").and.returnValue(stripeCaptureResult);

let captureResult = null;
let captureError = null;
Expand All @@ -103,11 +105,12 @@ describe("stripe/payment/capture", function () {
expect(captureError).to.be.undefined;
expect(captureResult).to.not.be.undefined;
expect(captureResult.saved).to.be.true;
expect(StripeApi.methods.captureCharge.call).to.have.been.calledWith({
expect(StripeApi.methods.captureCharge).to.have.been.calledWith({
transactionId: paymentMethod.transactionId,
captureDetails: {
amount: 1999
}
},
apiKey: apiKey
});
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("stripe/refund/create", function () {
receipt_number: null
};

sandbox.stub(StripeApi.methods.createRefund, "call", function () {
sandbox.stub(StripeApi.methods, "createRefund", function () {
return stripeRefundResult;
});
// spyOn(StripeApi.methods.createRefund, "call").and.returnValue(stripeRefundResult);
Expand All @@ -57,7 +57,7 @@ describe("stripe/refund/create", function () {
expect(refundError).to.be.undefined;
expect(refundResult).to.not.be.undefined;
expect(refundResult.saved).to.be.true;
expect(StripeApi.methods.createRefund.call).to.have.been.calledWith({
expect(StripeApi.methods.createRefund).to.have.been.calledWith({
refundDetails: {
charge: paymentMethod.transactionId,
amount: 1999,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("stripe/refunds/list", function () {
has_more: false,
url: "/v1/refunds"
};
sandbox.stub(StripeApi.methods.listRefunds, "call", function () {
sandbox.stub(StripeApi.methods, "listRefunds", function () {
return stripeRefundListResult;
});

Expand All @@ -69,7 +69,7 @@ describe("stripe/refunds/list", function () {
expect(refundListResult[0].amount).to.equal(19.99);
expect(refundListResult[0].currency).to.equal("usd");

expect(StripeApi.methods.listRefunds.call).to.have.been.calledWith({
expect(StripeApi.methods.listRefunds).to.have.been.calledWith({
transactionId: paymentMethod.transactionId
});
done();
Expand Down
Loading