Skip to content

Commit

Permalink
Merge pull request #111 from netflie/conversation-category-based-pricing
Browse files Browse the repository at this point in the history
conversation-category-based-pricing: add new conversation category ba…
  • Loading branch information
aalbarca authored Jun 1, 2023
2 parents 7f794bd + eee4158 commit f91e17e
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/WebHook/Notification/Support/ConversationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ final class ConversationType extends \MyCLabs\Enum\Enum
private const CUSTOMER_INITIATED = 'user_initiated';

private const REFERRAL_INITIATED = 'referral_conversion';

private const AUTHENTICATION = 'authentication';

private const MARKETING = 'marketing';

private const UTILITY = 'utility';

private const SERVICE = 'service';
}
232 changes: 232 additions & 0 deletions tests/Unit/WebHook/NotificationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,236 @@ public function test_build_from_payload_return_null_when_payload_is_empty()

$this->assertNull($notification);
}

public function test_build_from_payload_can_build_an_authentication_status_notification()
{
$payload = json_decode('{
"object": "whatsapp_business_account",
"entry": [
{
"id": "108536708899139",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "CUSTOMER_PHONE_NUMBER",
"phone_number_id": "CUSTOMER_PHONE_NUMBER"
},
"statuses": [
{
"id": "wamid.ID",
"status": "delivered",
"timestamp": "1685626673",
"recipient_id": "CUSTOMER_PHONE_NUMBER",
"conversation": {
"id": "CONVERSATION_ID",
"origin": {
"type": "authentication"
}
},
"pricing": {
"billable": true,
"pricing_model": "CBP",
"category": "authentication"
}
}
]
},
"field": "messages"
}
]
}
]
}', true);

$notification = $this->notification_factory->buildFromPayload($payload);

$this->assertInstanceOf(Notification\StatusNotification::class, $notification);
$this->assertEquals('wamid.ID', $notification->id());
$this->assertEquals('CUSTOMER_PHONE_NUMBER', $notification->customerId());
$this->assertEquals('CONVERSATION_ID', $notification->conversationId());
$this->assertFalse($notification->isBusinessInitiatedConversation());
$this->assertFalse($notification->isCustomerInitiatedConversation());
$this->assertFalse($notification->isReferralInitiatedConversation());
$this->assertEquals('authentication', $notification->conversationType());
$this->assertEquals('delivered', $notification->status());
$this->assertFalse($notification->isMessageRead());
$this->assertTrue($notification->isMessageDelivered());
$this->assertTrue($notification->isMessageSent());
}

public function test_build_from_payload_can_build_a_marketing_status_notification()
{
$payload = json_decode('{
"object": "whatsapp_business_account",
"entry": [
{
"id": "108536708899139",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "CUSTOMER_PHONE_NUMBER",
"phone_number_id": "CUSTOMER_PHONE_NUMBER"
},
"statuses": [
{
"id": "wamid.ID",
"status": "delivered",
"timestamp": "1685626673",
"recipient_id": "CUSTOMER_PHONE_NUMBER",
"conversation": {
"id": "CONVERSATION_ID",
"origin": {
"type": "marketing"
}
},
"pricing": {
"billable": true,
"pricing_model": "CBP",
"category": "marketing"
}
}
]
},
"field": "messages"
}
]
}
]
}', true);

$notification = $this->notification_factory->buildFromPayload($payload);

$this->assertInstanceOf(Notification\StatusNotification::class, $notification);
$this->assertEquals('wamid.ID', $notification->id());
$this->assertEquals('CUSTOMER_PHONE_NUMBER', $notification->customerId());
$this->assertEquals('CONVERSATION_ID', $notification->conversationId());
$this->assertFalse($notification->isBusinessInitiatedConversation());
$this->assertFalse($notification->isCustomerInitiatedConversation());
$this->assertFalse($notification->isReferralInitiatedConversation());
$this->assertEquals('marketing', $notification->conversationType());
$this->assertEquals('delivered', $notification->status());
$this->assertFalse($notification->isMessageRead());
$this->assertTrue($notification->isMessageDelivered());
$this->assertTrue($notification->isMessageSent());
}

public function test_build_from_payload_can_build_an_utility_status_notification()
{
$payload = json_decode('{
"object": "whatsapp_business_account",
"entry": [
{
"id": "108536708899139",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "CUSTOMER_PHONE_NUMBER",
"phone_number_id": "CUSTOMER_PHONE_NUMBER"
},
"statuses": [
{
"id": "wamid.ID",
"status": "delivered",
"timestamp": "1685626673",
"recipient_id": "CUSTOMER_PHONE_NUMBER",
"conversation": {
"id": "CONVERSATION_ID",
"origin": {
"type": "utility"
}
},
"pricing": {
"billable": true,
"pricing_model": "CBP",
"category": "utility"
}
}
]
},
"field": "messages"
}
]
}
]
}', true);

$notification = $this->notification_factory->buildFromPayload($payload);

$this->assertInstanceOf(Notification\StatusNotification::class, $notification);
$this->assertEquals('wamid.ID', $notification->id());
$this->assertEquals('CUSTOMER_PHONE_NUMBER', $notification->customerId());
$this->assertEquals('CONVERSATION_ID', $notification->conversationId());
$this->assertFalse($notification->isBusinessInitiatedConversation());
$this->assertFalse($notification->isCustomerInitiatedConversation());
$this->assertFalse($notification->isReferralInitiatedConversation());
$this->assertEquals('utility', $notification->conversationType());
$this->assertEquals('delivered', $notification->status());
$this->assertFalse($notification->isMessageRead());
$this->assertTrue($notification->isMessageDelivered());
$this->assertTrue($notification->isMessageSent());
}

public function test_build_from_payload_can_build_a_service_status_notification()
{
$payload = json_decode('{
"object": "whatsapp_business_account",
"entry": [
{
"id": "108536708899139",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "CUSTOMER_PHONE_NUMBER",
"phone_number_id": "CUSTOMER_PHONE_NUMBER"
},
"statuses": [
{
"id": "wamid.ID",
"status": "delivered",
"timestamp": "1685626673",
"recipient_id": "CUSTOMER_PHONE_NUMBER",
"conversation": {
"id": "CONVERSATION_ID",
"origin": {
"type": "service"
}
},
"pricing": {
"billable": true,
"pricing_model": "CBP",
"category": "service"
}
}
]
},
"field": "messages"
}
]
}
]
}', true);

$notification = $this->notification_factory->buildFromPayload($payload);

$this->assertInstanceOf(Notification\StatusNotification::class, $notification);
$this->assertEquals('wamid.ID', $notification->id());
$this->assertEquals('CUSTOMER_PHONE_NUMBER', $notification->customerId());
$this->assertEquals('CONVERSATION_ID', $notification->conversationId());
$this->assertFalse($notification->isBusinessInitiatedConversation());
$this->assertFalse($notification->isCustomerInitiatedConversation());
$this->assertFalse($notification->isReferralInitiatedConversation());
$this->assertEquals('service', $notification->conversationType());
$this->assertEquals('delivered', $notification->status());
$this->assertFalse($notification->isMessageRead());
$this->assertTrue($notification->isMessageDelivered());
$this->assertTrue($notification->isMessageSent());
}
}

0 comments on commit f91e17e

Please sign in to comment.