PHP code example of 3neti / x-affiliation

1. Go to this page and download the library: Download 3neti/x-affiliation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

3neti / x-affiliation example snippets


use LBHurtado\XAffiliation\Actions\EnsureApplicationInstanceNetwork;

$network = app(EnsureApplicationInstanceNetwork::class)->handle(
    installationReference: $stableInstallationUuid,
);

use LBHurtado\XAffiliation\Contracts\AffiliationIdentityKeyFactoryContract;

$mobileKey = app(AffiliationIdentityKeyFactoryContract::class)->forMobile(
    networkReference: $network->reference,
    canonicalMobile: '+639173011987',
);

use LBHurtado\XAffiliation\Actions\EnrollAffiliationMember;

$alice = app(EnrollAffiliationMember::class)->handle(
    network: $network,
    subjectType: 'account',
    subjectReference: 'account:alice',
    mobileKey: $aliceMobileKey,
    sourceType: 'commissioning',
    sourceReference: 'commissioning:alice',
);

use LBHurtado\XAffiliation\Actions\CheckSponsorshipEligibility;

$eligibility = app(CheckSponsorshipEligibility::class)->handle(
    network: $network,
    sponsorSubjectType: 'account',
    sponsorSubjectReference: 'account:alice',
    candidateMobileKey: $bobMobileKey,
);

if (! $eligibility->isEligible()) {
    // Map the typed reason to privacy-safe host copy.
}

use Carbon\CarbonImmutable;
use LBHurtado\XAffiliation\Actions\EstablishSponsorship;
use LBHurtado\XAffiliation\Data\SponsorshipAuthorityData;

$sponsorship = app(EstablishSponsorship::class)->handle(
    new SponsorshipAuthorityData(
        networkReference: $network->reference,
        sponsorSubjectType: 'account',
        sponsorSubjectReference: 'account:alice',
        memberSubjectType: 'account',
        memberSubjectReference: 'account:bob',
        memberMobileKey: $bobMobileKey,
        authorityType: 'x-provisioning-offer',
        authorityReference: '01K...',
        effectiveAt: CarbonImmutable::now(),
    ),
);

use LBHurtado\XAffiliation\Queries\GetAffiliationAncestors;
use LBHurtado\XAffiliation\Queries\GetAffiliationDescendants;

$ancestors = app(GetAffiliationAncestors::class)->handle($member);
$descendants = app(GetAffiliationDescendants::class)->handle($sponsor);

$this->app->singleton(
    AffiliationEventSinkContract::class,
    XJournalAffiliationEventSink::class,
);
bash
php artisan vendor:publish --tag=x-affiliation-config
php artisan vendor:publish --tag=x-affiliation-migrations