Fix Wren API request body to match official API specification
All checks were successful
Build and Push Docker Images / docker (push) Successful in 45s
All checks were successful
Build and Push Docker Images / docker (push) Successful in 45s
Changed request parameters to match Wren API docs: - 'portfolio' → 'portfolioId' (correct parameter name) - 'dry_run' → 'dryRun' (camelCase as per API) - Removed 'currency' and 'amount_charged' (API calculates amount) - Removed 'source' object (not in API spec) - Added 'note' with customer email for record keeping API will now calculate and return the amount charged based on tons and portfolio. Reference: https://www.wren.co/api/offset-orders documentation
This commit is contained in:
parent
a6e655c4a9
commit
837411699f
@ -231,8 +231,6 @@ async function fulfillOrder(order, session) {
|
||||
tons: order.tons,
|
||||
portfolioId: order.portfolio_id,
|
||||
customerEmail: session.customer_details?.email || order.customer_email,
|
||||
currency: order.currency,
|
||||
amountCents: order.total_amount,
|
||||
dryRun: isDryRun,
|
||||
});
|
||||
|
||||
|
||||
@ -7,18 +7,14 @@ const WREN_API_BASE_URL = 'https://www.wren.co/api';
|
||||
* @param {Object} orderData - Order data
|
||||
* @param {number} orderData.tons - Number of tons to offset
|
||||
* @param {number} orderData.portfolioId - Portfolio ID
|
||||
* @param {string} orderData.customerEmail - Customer email
|
||||
* @param {string} orderData.currency - Currency code
|
||||
* @param {number} orderData.amountCents - Amount in cents
|
||||
* @param {string} orderData.customerEmail - Customer email (included in note)
|
||||
* @param {boolean} orderData.dryRun - Dry run mode (default: false)
|
||||
* @returns {Promise<Object>} Wren order response
|
||||
* @returns {Promise<Object>} Wren order response with amountCharged, currency, portfolio, tons
|
||||
*/
|
||||
export async function createWrenOffsetOrder({
|
||||
tons,
|
||||
portfolioId,
|
||||
customerEmail,
|
||||
currency,
|
||||
amountCents,
|
||||
dryRun = false
|
||||
}) {
|
||||
const startTime = Date.now();
|
||||
@ -32,10 +28,8 @@ export async function createWrenOffsetOrder({
|
||||
console.log('🔵 [WREN API SERVER] Parameters:', JSON.stringify({
|
||||
tons: parseFloat(tons),
|
||||
portfolioId,
|
||||
customerEmail,
|
||||
currency: currency.toUpperCase(),
|
||||
amountCents,
|
||||
dryRun
|
||||
dryRun,
|
||||
note: `Puffin App order - Customer: ${customerEmail}`
|
||||
}, null, 2));
|
||||
|
||||
if (!apiToken) {
|
||||
@ -48,14 +42,9 @@ export async function createWrenOffsetOrder({
|
||||
`${WREN_API_BASE_URL}/offset-orders`,
|
||||
{
|
||||
tons: parseFloat(tons),
|
||||
portfolio: portfolioId,
|
||||
currency: currency.toUpperCase(),
|
||||
amount_charged: amountCents,
|
||||
dry_run: dryRun,
|
||||
source: {
|
||||
name: 'Puffin App',
|
||||
email: customerEmail
|
||||
}
|
||||
portfolioId: portfolioId,
|
||||
dryRun: dryRun,
|
||||
note: `Puffin App order - Customer: ${customerEmail}`
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user