-
Notifications
You must be signed in to change notification settings - Fork 5.5k
17438 afosto #18476
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
Open
luancazarine
wants to merge
6
commits into
master
Choose a base branch
from
17438-afosto
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
17438 afosto #18476
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd15883
Implement Afosto cart actions and update component structure
luancazarine 40a1a0d
pnpm update
luancazarine 2f20f95
Merge branch 'master' into 17438-afosto
luancazarine 5c48cd9
pnpm update
luancazarine 8bd3d5e
Remove optional flag from billing address fields and correct paramete…
luancazarine 0440eb9
Add Afosto cart mutations and refactor actions to utilize them
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
components/afosto/actions/add-information-to-cart/add-information-to-cart.mjs
This file contains hidden or 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,168 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import app from "../../afosto.app.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "afosto-add-information-to-cart", | ||
name: "Add Information to Cart", | ||
description: "Add customer information to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
cartId: { | ||
propDefinition: [ | ||
app, | ||
"cartId", | ||
], | ||
}, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email of the customer", | ||
optional: true, | ||
}, | ||
isGuest: { | ||
type: "boolean", | ||
label: "Is Guest", | ||
description: "Whether the customer is a guest", | ||
optional: true, | ||
}, | ||
givenName: { | ||
type: "string", | ||
label: "Given Name", | ||
description: "The given name of the customer", | ||
optional: true, | ||
}, | ||
additionalName: { | ||
type: "string", | ||
label: "Additional Name", | ||
description: "The additional name of the customer", | ||
optional: true, | ||
}, | ||
familyName: { | ||
type: "string", | ||
label: "Family Name", | ||
description: "The family name of the customer", | ||
optional: true, | ||
}, | ||
organisationName: { | ||
type: "string", | ||
label: "Organisation Name", | ||
description: "The name of the organisation", | ||
optional: true, | ||
}, | ||
organisationIsGuest: { | ||
type: "boolean", | ||
label: "Organisation Is Guest", | ||
description: "Whether the organisation is a guest", | ||
optional: true, | ||
}, | ||
organisationEmail: { | ||
type: "string", | ||
label: "Organisation Email", | ||
description: "The email of the organisation", | ||
optional: true, | ||
}, | ||
organisationCountryCode: { | ||
type: "string", | ||
label: "Organisation Country Code", | ||
description: "The country code of the organisation", | ||
optional: true, | ||
}, | ||
organisationNumber: { | ||
type: "string", | ||
label: "Organisation Number", | ||
description: "The number of the organisation", | ||
optional: true, | ||
}, | ||
countryCode: { | ||
type: "string", | ||
label: "Phone Number Country Code", | ||
description: "The country code of the phone number", | ||
optional: true, | ||
}, | ||
number: { | ||
type: "string", | ||
label: "Phone Number", | ||
description: "The number of the phone number", | ||
optional: true, | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shippingAddressData: { | ||
type: "object", | ||
label: "Shipping Address Data", | ||
description: "The shipping address data. **E.g. {\"country_code\": \"US\", \"postal_code\": \"10001\", \"address_line_1\": \"123 Main St\", \"given_name\": \"John\", \"family_name\": \"Smith\", \"organisation\": \"Organization Name\"}** [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)", | ||
}, | ||
billingAddressData: { | ||
type: "object", | ||
label: "Billing Address Data", | ||
description: "The billing address data. **E.g. {\"country_code\": \"US\", \"postal_code\": \"10001\", \"address_line_1\": \"123 Main St\", \"given_name\": \"John\", \"family_name\": \"Smith\", \"organisation\": \"Organization Name\"}** [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/collecting-customer-data/)", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const cartId = this.cartId; | ||
|
||
const phoneNumberData = { | ||
country_code: this.countryCode, | ||
number: this.number, | ||
}; | ||
|
||
const parsedBillingAddressData = parseObject(this.billingAddressData); | ||
|
||
const variables = { | ||
customerInput: { | ||
cart_id: cartId, | ||
customer: { | ||
contact: { | ||
email: this.email, | ||
is_guest: this.isGuest, | ||
given_name: this.givenName, | ||
additional_name: this.additionalName, | ||
family_name: this.familyName, | ||
phone_numbers: [ | ||
phoneNumberData, | ||
], | ||
}, | ||
organisation: { | ||
name: this.organisationName, | ||
is_guest: this.organisationIsGuest, | ||
administration: { | ||
email: this.organisationEmail, | ||
}, | ||
registration: { | ||
country_code: this.organisationCountryCode, | ||
number: this.organisationNumber, | ||
}, | ||
}, | ||
}, | ||
}, | ||
phoneNumberInput: { | ||
cart_id: cartId, | ||
phone_number: phoneNumberData, | ||
}, | ||
shippingAddressInput: { | ||
address: parseObject(this.shippingAddressData), | ||
cart_id: cartId, | ||
type: "ADDRESS", | ||
}, | ||
billingAddressInput: { | ||
address: parsedBillingAddressData, | ||
cart_id: cartId, | ||
}, | ||
countryCode: parsedBillingAddressData?.country_code, | ||
postalCode: parsedBillingAddressData?.postal_code, | ||
}; | ||
|
||
const response = await this.app.addInformationToCart({ | ||
$, | ||
variables, | ||
}); | ||
|
||
if (response.errors) { | ||
throw new ConfigurationError(JSON.stringify(response.errors[0])); | ||
} | ||
|
||
$.export("$summary", `Successfully added information to cart with ID: ${this.cartId}`); | ||
return response.data; | ||
}, | ||
}; |
51 changes: 51 additions & 0 deletions
51
components/afosto/actions/add-item-to-cart/add-item-to-cart.mjs
This file contains hidden or 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,51 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import app from "../../afosto.app.mjs"; | ||
|
||
export default { | ||
key: "afosto-add-item-to-cart", | ||
name: "Add Item to Cart", | ||
description: "Add an item to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/add-and-remove-items/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
sku: { | ||
type: "string", | ||
label: "SKU", | ||
description: "The SKU of the item to add to the cart.", | ||
}, | ||
quantity: { | ||
type: "integer", | ||
label: "Quantity", | ||
description: "The quantity of the item to add to the cart.", | ||
}, | ||
cartId: { | ||
propDefinition: [ | ||
app, | ||
"cartId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.addItemToCart({ | ||
$, | ||
variables: { | ||
input: { | ||
cart_id: this.cartId, | ||
items: [ | ||
{ | ||
sku: this.sku, | ||
quantity: this.quantity, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
if (response.errors) { | ||
throw new ConfigurationError(JSON.stringify(response.errors[0])); | ||
} | ||
$.export("$summary", `Successfully added item to cart with SKU: ${response.data.addItemsToCart.cart.items[0].sku}`); | ||
return response.data.addItemsToCart.cart; | ||
}, | ||
}; |
42 changes: 42 additions & 0 deletions
42
components/afosto/actions/add-note-to-cart/add-note-to-cart.mjs
This file contains hidden or 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,42 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import app from "../../afosto.app.mjs"; | ||
|
||
export default { | ||
key: "afosto-add-note-to-cart", | ||
name: "Add Note to Cart", | ||
description: "Add a note to a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/checkout-summary/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
cartId: { | ||
propDefinition: [ | ||
app, | ||
"cartId", | ||
], | ||
}, | ||
note: { | ||
type: "string", | ||
label: "Note", | ||
description: "The note to add to the cart", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const variables = { | ||
cartId: this.cartId, | ||
note: this.note, | ||
}; | ||
|
||
const response = await this.app.addNoteToCart({ | ||
$, | ||
variables, | ||
}); | ||
|
||
if (response.errors) { | ||
throw new ConfigurationError(JSON.stringify(response.errors[0])); | ||
} | ||
|
||
$.export("$summary", `Successfully added note to cart with ID: ${this.cartId}`); | ||
return response.data.setNoteForCart.cart; | ||
}, | ||
}; |
This file contains hidden or 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,34 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import app from "../../afosto.app.mjs"; | ||
|
||
export default { | ||
key: "afosto-confirm-cart", | ||
name: "Confirm Cart", | ||
description: "Confirm a cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/custom-checkout/payment-process/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
cartId: { | ||
propDefinition: [ | ||
app, | ||
"cartId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.confirmCart({ | ||
$, | ||
variables: { | ||
cartId: this.cartId, | ||
}, | ||
}); | ||
|
||
if (response.errors) { | ||
throw new ConfigurationError(JSON.stringify(response.errors[0])); | ||
} | ||
|
||
$.export("$summary", `Successfully confirmed cart with ID: ${response.data.confirmCart.order.id}`); | ||
return response.data.confirmCart.order; | ||
}, | ||
}; |
This file contains hidden or 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,25 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import app from "../../afosto.app.mjs"; | ||
|
||
export default { | ||
key: "afosto-create-cart", | ||
name: "Create Cart", | ||
description: "Create a new cart. [See the documentation](https://afosto.com/docs/developers/storefront-js-client/integration/create-a-cart/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.createCart({ | ||
$, | ||
}); | ||
|
||
if (response.errors) { | ||
throw new ConfigurationError(JSON.stringify(response.errors[0])); | ||
} | ||
|
||
$.export("$summary", `Successfully created cart with ID: ${response.data.createCart.cart.id}`); | ||
return response.data.createCart.cart; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.