PHPackages                             remp/crm-gifts-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. remp/crm-gifts-module

ActiveLibrary

remp/crm-gifts-module
=====================

CRM Gifts Module

4.4.0(10mo ago)015.6k↓20.6%1MITPHPPHP ^8.1

Since Nov 29Pushed 5mo ago7 watchersCompare

[ Source](https://github.com/remp2020/crm-gifts-module)[ Packagist](https://packagist.org/packages/remp/crm-gifts-module)[ Docs](https://remp2030.com)[ RSS](/packages/remp-crm-gifts-module/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (67)Used By (1)

CRM GiftsModule
===============

[](#crm-giftsmodule)

[![Translation status @ Weblate](https://camo.githubusercontent.com/42e620130d9e8414cf3ab5344dcef3c7d5b5bcd96be53cec93cc11d9cd70fdfa/68747470733a2f2f686f737465642e7765626c6174652e6f72672f776964676574732f72656d702d63726d2f2d2f67696674732d6d6f64756c652f7376672d62616467652e737667)](https://hosted.weblate.org/projects/remp-crm/gifts-module/)

This module provides gift option to [SalesFunnelModule](https://github.com/remp2020/crm-salesfunnel-module/).

Installing module
-----------------

[](#installing-module)

We recommend using Composer for installation and update management.

```
composer require remp/crm-gifts-module
```

### Enabling module

[](#enabling-module)

Add installed extension to your `app/config/config.neon` file:

```
extensions:
	- Crm\GiftsModule\DI\GiftsModuleExtension
```

Run service commands to generate CRM internals:

```
php bin/command.php phinx:migrate
php bin/command.php user:generate_access
php bin/command.php api:generate_access
php bin/command.php application:seed

```

[SalesFunnelModule](https://github.com/remp2020/crm-salesfunnel-module/) integration
------------------------------------------------------------------------------------

[](#salesfunnelmodule-integration)

1. Add to your sales funnel `payment_metadata` fields *(have to be sent together with other required sales funnel's fields; see [SalesFunnelModule](https://github.com/remp2020/crm-salesfunnel-module/) README)*:

    - `payment_metadata[gift]` *(boolean)* - if true, indicates that this purchase is gift.
    - `payment_metadata[gift_email]` *(string)* - email of customer for which is gift purchased. This can be email of existing or new customer. Gift process handles creation of new accounts.
    - `payment_metadata[gift_starts_at]` *(string)* - date when should gifted subscription start. Use `DateTimeInterface::RFC3339`.

    **All three fields are mandatory**.
2. Put `php bin/command.php gifts:activate_purchased_gift_coupons` into cron. We recommend running it every 5 to 10 minutes.
3. Create event listeners for these `NotificationEvent`s if you want to inform customers about gift related events:

    - `created_payment_gift_coupon` - emitted when payment for gift subscription for confirmed *(paid)*. Send to donor.
    - `welcome_email_gift_coupon` - emitted when gift subscription was created *(gift subscription is created by command from previous step at `gift_starts_at` datetime)* and donee's account was created in CRM. Send to donee *(email from `gift_email` field)*.
    - `new_subscription_gift` - emitted when gift subscription was created *(gift subscription is created by command from previous step at `gift_starts_at` datetime)* and donee's account already existed in CRM. Send to donee *(email from `gift_email` field)*.
4. Set gift coupon attachment which should be attached to notification event sent to donor. See application config `gift_subscription_coupon_attachment`, can be found in web administration under category `Subscriptions`.

### How it works

[](#how-it-works)

1. `PaymentItemContainerReadyEventHandler` listens to `PaymentItemContainerReadyEvent`.

    - If `payment_metadata` contains valid gift fields *(see above)*, it switches `SubscriptionTypePaymentItem` to `GiftPaymentItem`.
2. `CreateGiftCouponNewPaymentEventHandler` listens to `NewPaymentEvent` *(payment is created; not paid)*.

    - If `payment_meta` contains valid gift fields, it removes `subscription_type_id` from Payment *(to prevent creation of subscription for donor's account)*.
    - Afterwords it creates `payment_gift_coupons` entry from gift fields.
        - *This is created before payment is confirmed for legacy reasons. This helps helpdesk to search and to pair payment with gifts.*
3. `GiftPaymentStatusChangeHandler` listens to `PaymentChangeStatusEvent`.

    - If payment is PAID and it is gift subscription purchase *(payment's meta contains `gift === 1`)*, `NotificationEvent(created_payment_gift_coupon)` with coupon attached *(see integration)* is emitted.
4. Command `php bin/command.php gifts:activate_purchased_gift_coupons` is running in background and activating gift subscriptions when time &gt;= `gift_starts_at`.

    - Donee account:
        - If account with `gift_email` exists, it is used for gift.
        - Otherwise new account is created with `user.source = PaymentGiftCouponsRepository::USER_SOURCE_GIFT_COUPON`.
    - New subscription is attached to donee's account with `subscription.type = SubscriptionsRepository::TYPE_GIFT`.
    - You can configure subscription extension method by calling `setExtendMethod` in your configuration file like this:

    ```
    activatePurchasedGiftCouponsCommand:
    	setup:
    		- setExtendMethod('extend_same_content_access')
    ```
5. `SendWelcomeEmailHandler` listens to `UserRegisteredEvent`.

    - If created user has `source === PaymentGiftCouponsRepository::USER_SOURCE_GIFT_COUPON`, `NotificationEvent(welcome_email_gift_coupon)` is emitted.
6. `SubscriptionsStartsEventHandler` listens to `SubscriptionStartsEvent`.

    - If subscription has `type === SubscriptionsRepository::TYPE_GIFT` and account wasn't created in last 15 minutes *(by command)*, `NotificationEvent(new_subscription_gift)` is emitted.

Notification email after the payment
------------------------------------

[](#notification-email-after-the-payment)

Both of the following options require [REMP Mailer](https://github.com/remp2020/mailer-skeleton/) integration, or other custom implementation handling `NotificationEvent`.

### Default email

[](#default-email)

If you want to just use the defaults provided by the module, you can enable the event handler responsible for sending the notification email. In one of your custom (internal) modules, add this snippet:

```
