@oficialapi/sdk 7.0.0 → 8.0.0

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.
Files changed (2) hide show
  1. package/README.md +236 -24
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -341,32 +341,35 @@ await sdk.whatsapp.sendDocument({
341
341
 
342
342
  #### Enviar Pedido com Opções de Pagamento
343
343
 
344
+ > **⚠️ Nota Importante:** O status do pedido deve ser `pending` ao usar `sendOrderDetails`. Use `sendOrderStatus` para atualizar o status após o pagamento.
345
+
346
+ **Exemplo 1: Pedido Digital com PIX**
347
+
344
348
  ```typescript
345
349
  await sdk.whatsapp.sendOrderDetails({
346
- token: 'sk_live_...',
350
+ token: 'sk_live_9999999999999999999999999',
347
351
  sender: '5511999999999',
348
- headerText: 'Confirmação de Pedido', // Opcional
352
+ headerText: 'Confirmação de Pedido',
349
353
  bodyText: 'Seu pedido #12345 está pronto para pagamento!',
350
- footerText: 'Obrigado por comprar conosco!', // Opcional
351
- reference_id: 'pedido_12345_1704067200', // ID único do pedido
352
- type: 'digital-goods', // ou 'physical-goods'
354
+ footerText: 'Obrigado por comprar conosco!',
355
+ reference_id: 'pedido_12345_1704067200',
356
+ type: 'digital-goods',
353
357
  currency: 'BRL',
354
358
  total_amount: {
355
- value: 50000, // Valor em centavos (500.00)
356
- offset: 100, // Fator de ajuste (sempre 100 para BRL)
357
- description: 'Total do pedido' // Opcional
359
+ value: 50000,
360
+ offset: 100
358
361
  },
359
362
  order: {
360
- status: 'pending',
363
+ status: 'pending', // OBRIGATÓRIO: deve ser 'pending' para review_and_pay
361
364
  items: [
362
365
  {
363
366
  retailer_id: '1234567',
364
- name: 'Produto 1',
367
+ name: 'Cake',
365
368
  amount: {
366
369
  value: 50000,
367
370
  offset: 100
368
371
  },
369
- quantity: 2
372
+ quantity: 1
370
373
  }
371
374
  ],
372
375
  subtotal: {
@@ -377,39 +380,248 @@ await sdk.whatsapp.sendOrderDetails({
377
380
  value: 0,
378
381
  offset: 100,
379
382
  description: 'Sem impostos'
383
+ }
384
+ },
385
+ payment_settings: [
386
+ {
387
+ type: 'pix_dynamic_code',
388
+ pix_dynamic_code: {
389
+ code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
390
+ merchant_name: 'Minha Empresa Ltda',
391
+ key: '39580525000189',
392
+ key_type: 'CNPJ'
393
+ }
394
+ }
395
+ ]
396
+ }, accessToken);
397
+ ```
398
+
399
+ **Exemplo 2: Pedido Digital com Link de Pagamento**
400
+
401
+ ```typescript
402
+ await sdk.whatsapp.sendOrderDetails({
403
+ token: 'sk_live_9999999999999999999999999',
404
+ sender: '5511999999999',
405
+ bodyText: 'Sua fatura está disponível para pagamento!',
406
+ reference_id: 'fatura_67890_1704067200',
407
+ type: 'digital-goods',
408
+ currency: 'BRL',
409
+ total_amount: {
410
+ value: 150000,
411
+ offset: 100
412
+ },
413
+ order: {
414
+ status: 'pending',
415
+ items: [
416
+ {
417
+ retailer_id: 'item_001',
418
+ name: 'Serviço Premium',
419
+ amount: {
420
+ value: 150000,
421
+ offset: 100
422
+ },
423
+ quantity: 1
424
+ }
425
+ ],
426
+ subtotal: {
427
+ value: 150000,
428
+ offset: 100
380
429
  },
381
- shipping: { // Opcional
382
- value: 1000,
383
- offset: 100,
384
- description: 'Frete'
430
+ tax: {
431
+ value: 0,
432
+ offset: 100
433
+ }
434
+ },
435
+ payment_settings: [
436
+ {
437
+ type: 'payment_link',
438
+ payment_link: {
439
+ uri: 'https://pagamento.exemplo.com/fatura/67890'
440
+ }
441
+ }
442
+ ]
443
+ }, accessToken);
444
+ ```
445
+
446
+ **Exemplo 3: Pedido Digital com Boleto**
447
+
448
+ ```typescript
449
+ await sdk.whatsapp.sendOrderDetails({
450
+ token: 'sk_live_9999999999999999999999999',
451
+ sender: '5511999999999',
452
+ bodyText: 'Sua inscrição está confirmada! Efetue o pagamento via boleto.',
453
+ reference_id: 'inscricao_11111_1704067200',
454
+ type: 'digital-goods',
455
+ currency: 'BRL',
456
+ total_amount: {
457
+ value: 29900,
458
+ offset: 100
459
+ },
460
+ order: {
461
+ status: 'pending',
462
+ items: [
463
+ {
464
+ retailer_id: 'curso_001',
465
+ name: 'Curso de Programação',
466
+ amount: {
467
+ value: 29900,
468
+ offset: 100
469
+ },
470
+ quantity: 1
471
+ }
472
+ ],
473
+ subtotal: {
474
+ value: 29900,
475
+ offset: 100
476
+ },
477
+ tax: {
478
+ value: 0,
479
+ offset: 100
480
+ }
481
+ },
482
+ payment_settings: [
483
+ {
484
+ type: 'boleto',
485
+ boleto: {
486
+ digitable_line: '03399026944140000002628346101018898510000008848'
487
+ }
488
+ }
489
+ ]
490
+ }, accessToken);
491
+ ```
492
+
493
+ **Exemplo 4: Pedido Físico com Múltiplas Formas de Pagamento (PIX + Link)**
494
+
495
+ ```typescript
496
+ await sdk.whatsapp.sendOrderDetails({
497
+ token: 'sk_live_9999999999999999999999999',
498
+ sender: '5511999999999',
499
+ bodyText: 'Seu pedido está pronto! Escolha a forma de pagamento:',
500
+ reference_id: 'pedido_completo_22222_1704067200',
501
+ type: 'physical-goods',
502
+ currency: 'BRL',
503
+ total_amount: {
504
+ value: 262400, // subtotal (259900) + tax (0) + shipping (2500) - discount (0)
505
+ offset: 100
506
+ },
507
+ order: {
508
+ status: 'pending',
509
+ catalog_id: '1234567890',
510
+ items: [
511
+ {
512
+ retailer_id: 'produto_001',
513
+ name: 'Camiseta Básica',
514
+ amount: {
515
+ value: 79000,
516
+ offset: 100
517
+ },
518
+ quantity: 2
519
+ },
520
+ {
521
+ retailer_id: 'produto_002',
522
+ name: 'Calça Jeans',
523
+ amount: {
524
+ value: 101900,
525
+ offset: 100
526
+ },
527
+ quantity: 1
528
+ }
529
+ ],
530
+ subtotal: {
531
+ value: 259900,
532
+ offset: 100
385
533
  },
386
- discount: { // Opcional
387
- value: 5000,
534
+ tax: {
535
+ value: 0,
536
+ offset: 100
537
+ },
538
+ shipping: {
539
+ value: 2500,
388
540
  offset: 100,
389
- description: 'Desconto',
390
- discount_program_name: 'Promoção'
541
+ description: 'Frete via SEDEX'
391
542
  }
392
543
  },
393
- payment_settings: [ // Opcional, máximo 2 métodos
544
+ payment_settings: [
394
545
  {
395
546
  type: 'pix_dynamic_code',
396
547
  pix_dynamic_code: {
397
548
  code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
398
- merchant_name: 'Minha Empresa Ltda',
399
- key: '39580525000189',
400
- key_type: 'CNPJ' // CPF, CNPJ, EMAIL, PHONE ou EVP
549
+ merchant_name: 'Minha Loja Virtual',
550
+ key: 'minhaloja@email.com',
551
+ key_type: 'EMAIL'
401
552
  }
402
553
  },
403
554
  {
404
555
  type: 'payment_link',
405
556
  payment_link: {
406
- uri: 'https://pagamento.exemplo.com/pedido/123'
557
+ uri: 'https://minhaloja.com/pagar/22222'
407
558
  }
408
559
  }
409
560
  ]
410
561
  }, accessToken);
411
562
  ```
412
563
 
564
+ **Exemplo 5: Pedido com Desconto (Black Friday)**
565
+
566
+ ```typescript
567
+ await sdk.whatsapp.sendOrderDetails({
568
+ token: 'sk_live_9999999999999999999999999',
569
+ sender: '5511999999999',
570
+ bodyText: 'Black Friday! Seu pedido com desconto especial:',
571
+ reference_id: 'black_friday_33333_1704067200',
572
+ type: 'digital-goods',
573
+ currency: 'BRL',
574
+ total_amount: {
575
+ value: 39900, // subtotal (49900) + tax (0) + shipping (0) - discount (10000)
576
+ offset: 100
577
+ },
578
+ order: {
579
+ status: 'pending',
580
+ items: [
581
+ {
582
+ retailer_id: 'bf_001',
583
+ name: 'Pacote Premium',
584
+ amount: {
585
+ value: 49900,
586
+ offset: 100
587
+ },
588
+ quantity: 1
589
+ }
590
+ ],
591
+ subtotal: {
592
+ value: 49900,
593
+ offset: 100
594
+ },
595
+ tax: {
596
+ value: 0,
597
+ offset: 100
598
+ },
599
+ discount: {
600
+ value: 10000,
601
+ offset: 100,
602
+ description: 'Desconto Black Friday 20%',
603
+ discount_program_name: 'Black Friday 2024'
604
+ }
605
+ },
606
+ payment_settings: [
607
+ {
608
+ type: 'pix_dynamic_code',
609
+ pix_dynamic_code: {
610
+ code: '00020101021226700014br.gov.bcb.pix2548pix.example.com...',
611
+ merchant_name: 'Black Friday Loja',
612
+ key: '5511999999999',
613
+ key_type: 'PHONE'
614
+ }
615
+ }
616
+ ]
617
+ }, accessToken);
618
+ ```
619
+
620
+ **Importante:**
621
+ - O `total_amount.value` deve ser igual a: `subtotal + tax + shipping - discount`
622
+ - O status do pedido deve ser `pending` ao usar `sendOrderDetails`
623
+ - Use `sendOrderStatus` para atualizar o status após o pagamento
624
+
413
625
  #### Atualizar Status do Pedido
414
626
 
415
627
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oficialapi/sdk",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "SDK oficial da OficialAPI - Integração completa com WhatsApp, Telegram, Facebook, Instagram e WebChat",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",