forked from hygraph/gatsby-graphcms-ecommerce-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Checkout mutation (hygraph#49)
* feat: Add Printful API datasource to Apollo Server With createOrder method to interact with API * feat: Update GCMS createOrder mutation to match schema * feat: Working mutation to create GCMS order on checkout * feat: Working mutation to create Printful order on checkout * simplify checkout form * feat: Add createPaymentIntentResolver * fix: Return required fields from Stripe * fix: Actually pass external_id field to Printful order create payload * feat: Use confirmCardPayment to confirm PaymentIntent * add Select form element * feat: Update checkout form to use shipping country listings from Printful Needs ynnoj/gatsby-source-printful#4 * chore: Bump to gatsby-source-printful@1.2.0 * refactor: Use form state for active shipping, billing countries logic * refactor: Use input with checkout mutation schema * chore: bump use-cart pkg
- Loading branch information
Jonathan Steele
authored
Dec 16, 2019
1 parent
cfa5704
commit 71c92a1
Showing
14 changed files
with
480 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const GraphCMSAPI = require('./graphcms'); | ||
const PrintfulAPI = require('./printful'); | ||
|
||
const datasources = () => ({ | ||
GraphCMSAPI: new GraphCMSAPI(), | ||
PrintfulAPI: new PrintfulAPI(), | ||
}); | ||
|
||
module.exports = datasources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { RESTDataSource } = require('apollo-datasource-rest'); | ||
|
||
class PrintfulAPI extends RESTDataSource { | ||
constructor() { | ||
super(); | ||
this.baseURL = 'https://api.printful.com'; | ||
} | ||
|
||
willSendRequest(request) { | ||
request.headers.set( | ||
'Authorization', | ||
`Basic ${Buffer.from(process.env.PRINTFUL_API_KEY).toString('base64')}` | ||
); | ||
} | ||
|
||
async createOrder({ external_id, items, recipient }) { | ||
try { | ||
const { result: data } = await this.post(`orders`, { | ||
external_id, | ||
items, | ||
recipient, | ||
}); | ||
|
||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
|
||
module.exports = PrintfulAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
functions/graphql/resolvers/mutation/createPaymentIntent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const createPaymentIntentResolver = async ( | ||
_, | ||
{ input: { email, metadata, total } }, | ||
{ stripe } | ||
) => { | ||
try { | ||
const { | ||
id, | ||
client_secret: clientSecret, | ||
status, | ||
} = await stripe.paymentIntents.create({ | ||
amount: total, | ||
currency: 'eur', | ||
metadata, | ||
receipt_email: email, | ||
}); | ||
|
||
return { | ||
id, | ||
clientSecret, | ||
status, | ||
}; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
module.exports = createPaymentIntentResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.