Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3defc755 authored by Nivesh Krishna's avatar Nivesh Krishna Committed by Arnau Vàzquez
Browse files

Reward user in respective shop location

parent fd697296
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -79,6 +79,13 @@ flags:
        name="ref"
        type="hidden"
      />
      <input
        class="requestInput"
        id="shop"
        name="shop"
        type="hidden"
      />

      <div class="field has-text-centered" id="buttonField">
        <div class="control">
          <button class="button button-primary is-rounded" id="submitButton" type="submit">
+4 −0
Original line number Diff line number Diff line
@@ -86,10 +86,14 @@ $(document).ready(function () {
      const queryString = window.location.search;
      const urlParams = new URLSearchParams(queryString);
      const referrerCode = urlParams.get('ref');
      const shopLocation = urlParams.get('shop')
      let endPoint = `/signup/process_email_invite.php?lang=${lang}`;
      if (referrerCode != null) {
        document.getElementById("ref").value = referrerCode;
      }
      if (shopLocation != null) {
        document.getElementById("shop").value = shopLocation;
      }
      $.post(
        endPoint,
        $("#inviteRequestForm").serialize(),
+2 −0
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ $(document).ready(function () {
        } else {

          const refCode = searchParams.has('ref')? searchParams.get('ref') : null;
          const shopLocation = searchParams.has('shop')? searchParams.get('shop') : null;

          //post data
          url = $("#registrationform").attr("action");
@@ -177,6 +178,7 @@ $(document).ready(function () {
              authmail: authmail,
              authsecret: authsecret,
              ref: refCode,
              shop: shopLocation,
              tosAccepted: tosAccepted,
            },
            function (response) {
+6 −3
Original line number Diff line number Diff line
@@ -5,11 +5,14 @@ class WPAccountCreator implements AccountCreator
{
    private string $wordPressUrl;
    private string $wordPressCredentials;
    public function __construct(string $wordPressUrl, string $username, string $appPassword)
    private string $wordPressUserUrl;
    public function __construct(string $wordPressUrl, string $username, string $appPassword, string $shopLocation = null)
    {
        $this->wordPressUrl = endsWith($wordPressUrl, "/") ? $wordPressUrl : $wordPressUrl . "/";
        $this->wordPressUserUrl = $this->wordPressUrl . "?rest_route=/wp/v2/users";
        $this->wordPressReferralRewardsUrl = $this->wordPressUrl . "?rest_route=/referral-program/v1/reward-referrer";
        if ($shopLocation) {
            $this->wordPressUrl .= $shopLocation . '/';
        }
        $this->wordPressCredentials = base64_encode($username . ":" . $appPassword);
    }
    public function validateData(object $userData): ValidatedData
@@ -110,7 +113,7 @@ class WPAccountCreator implements AccountCreator
            return false;
        }
        $curl = curl_init();
        $url = $this->wordPressReferralRewardsUrl;
        $url = $this->wordPressUrl . "?rest_route=/referral-program/v1/reward-referrer";
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
+7 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ $authmail = $_POST['authmail'];
$authsecret = $_POST['authsecret'];
$tosAccepted = isset($_POST['tosAccepted']) ? $_POST['tosAccepted'] : false;
$referrerCode = isset($_POST["ref"]) ? $_POST["ref"] : null;
$shopLocation = isset($_POST["shop"]) ? $_POST["shop"] : null;
$referrerCode = is_string($referrerCode) ? $referrerCode : null;
$resultmail = $mbox . "@" . $mail_domain;

@@ -182,6 +183,7 @@ function shouldRewardReferrer(object $userData): bool

function createAccounts(array $accountsCreators, object $userData)
{
    global $shopLocation;
    foreach ($accountsCreators as $accountCreator) {
        try {
            $accountCreator->tryToCreate($userData);
@@ -196,8 +198,11 @@ function createAccounts(array $accountsCreators, object $userData)
        $E_SHOP_URL = getenv("E_SHOP_URL");
        $E_SHOP_USERNAME = getenv("E_SHOP_USERNAME");
        $E_SHOP_APP_PASS = getenv("E_SHOP_APP_PASS");
        $wpShop = new \WPAccountCreator($E_SHOP_URL, $E_SHOP_USERNAME, $E_SHOP_APP_PASS);
        $status = $wpShop->sendWPRewardRequest($userData);
        if ($shopLocation) {
            $E_SHOP_APP_PASS = getenv("E_SHOP_APP_PASS_" . strtoupper($shopLocation));
        }
        $wpShop = new \WPAccountCreator($E_SHOP_URL, $E_SHOP_USERNAME, $E_SHOP_APP_PASS, $shopLocation);
        $status = $wpShop->sendWPRewardRequest($userData, $shopLocation);
    }
}

Loading