@sails-pay/bachs 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ function buildCustomerPayload(inputs) {
27
27
  })
28
28
  }
29
29
 
30
- return withoutUndefined({
30
+ const details = withoutUndefined({
31
31
  email:
32
32
  customer.email ||
33
33
  inputs.customerEmail ||
@@ -37,6 +37,9 @@ function buildCustomerPayload(inputs) {
37
37
  customer.name || inputs.customerName || inputs.name || checkoutData.name,
38
38
  phone_number: customer.phoneNumber || inputs.phoneNumber
39
39
  })
40
+
41
+ // Omit an absent identity so hosted checkout can collect guest details.
42
+ return Object.keys(details).length ? details : undefined
40
43
  }
41
44
 
42
45
  function buildProductCart(items) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sails-pay/bachs",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Bachs adapter for Sails Pay",
5
5
  "main": "adapter.js",
6
6
  "scripts": {
@@ -96,7 +96,6 @@ test('checkout sends custom pricing and the buyer-selected amount', async () =>
96
96
 
97
97
  assert.equal(checkoutUrl, 'https://pay.bachs.io/c/custom')
98
98
  assert.deepEqual(JSON.parse(calls[0].options.body), {
99
- customer: {},
100
99
  product_cart: [
101
100
  {
102
101
  product_id: 'prod_custom',
@@ -143,7 +142,6 @@ test('checkout prices itself with amount and currency', async () => {
143
142
  )
144
143
  assert.equal(calls[0].options.headers['Idempotency-Key'], 'pure_123')
145
144
  assert.deepEqual(JSON.parse(calls[0].options.body), {
146
- customer: {},
147
145
  pricing: {
148
146
  currency: 'USD',
149
147
  amount: '42.00'
@@ -580,3 +578,27 @@ for (const invalidCase of invalidConnectCases) {
580
578
  assert.equal(fetchCalls, 0)
581
579
  })
582
580
  }
581
+
582
+ for (const customer of [undefined, null, {}]) {
583
+ test(`guest checkout omits an empty customer (${JSON.stringify(
584
+ customer
585
+ )})`, async () => {
586
+ let payload
587
+ fetch.setFetchImplementation(async (url, options) => {
588
+ payload = JSON.parse(options.body)
589
+ return {
590
+ ok: true,
591
+ text: async () =>
592
+ JSON.stringify({ checkout_url: 'https://pay.bachs.io/c/guest' })
593
+ }
594
+ })
595
+ await checkout({
596
+ apiKey: 'sk_sandbox_test',
597
+ amount: '10.00',
598
+ currency: 'USD',
599
+ customer
600
+ })
601
+ assert.equal(Object.hasOwn(payload, 'customer'), false)
602
+ assert.equal(Object.hasOwn(payload, 'customer_creation'), false)
603
+ })
604
+ }