コード例 #1
0
ファイル: register.php プロジェクト: s3rge/webmasters-forge
    $values = "NOW(), '{$fieldValues->email}', '{$passwordHash}', '{$fieldValues->firstName}', " . "'{$fieldValues->lastName}', '{$fieldValues->married}', '{$fieldValues->city}', " . "'{$fieldValues->street}', '{$fieldValues->house}', '{$fieldValues->education}', '{$fieldValues->year}'";
    $nonRequiredColumns = ["phone", "phone2", "middleName", "apartment", "professionalExperience", "info", "image"];
    foreach ($fieldValues as $fieldName => $fieldValue) {
        foreach ($nonRequiredColumns as $nonRequiredColumn) {
            if ($fieldName == $nonRequiredColumn && $fieldValue) {
                $columns .= ", " . $nonRequiredColumn;
                $values .= ", '{$fieldValue}'";
            }
        }
    }
    $q = "insert into user ({$columns}) values ({$values})";
    db_query($dbLink, $q);
    $userId = mysqli_insert_id($dbLink);
    $sessionUid = open_session($dbLink, $userId, true);
} catch (DbException $e) {
    $error = "internalException";
} catch (Exceptioni $e) {
    $error = $e->getCode();
} finally {
    $responce = [];
    if ($error) {
        $responce["status"] = "error";
        $responce["error"] = $error;
        $responce["fieldErrors"] = $errors;
    } else {
        $responce["status"] = "ok";
        $responce["sessionUid"] = $sessionUid;
    }
    db_close($dbLink);
    respond_json($responce);
}
コード例 #2
0
function deposit()
{
    global $base_url;
    $api = get_api();
    if (isset($api)) {
        /* The messageid is the system local identifier for this request. It 
         * must be unique for each call and you can use it to tie this order to 
         * a local equivalent. A common mistake here is to tie this to a 
         * cart-id or similar that will be preserved if the user cancels the 
         * payment and re-selects the trustly method. This can be worked around 
         * by either locally saving the connection between the orderid (from 
         * trustly) and your local identifier or by using the local identifier 
         * in combination with a unique element to build the message id.
         *
         * Here we have no local information so I will simply randomize it. */
        $messageid = substr(md5(microtime()), 0, 16);
        /* Sending in an empty amount will cause the trustly iframe to present 
         * the user with an amount selector dialogue. For e-commerce payments 
         * this is not especially useful, but if you are dealing with an online 
         * wallet this can come in handy */
        $amount = $_GET['amount'];
        if (empty($amount)) {
            $amount = NULL;
        }
        if (isset($amount)) {
            $amount = number_format($amount, 2, '.', '');
        }
        $currency = $_GET['currency'];
        if (empty($currency)) {
            respond_json(200, array('result' => 'error', 'error' => 'No currency given'));
            return;
        }
        /* We need to send in the remote client address, this is normally not 
         * as simple as just looking at the REMOTE_ADDR field as this can point 
         * to internal proxies etc. */
        $ip = $_SERVER['REMOTE_ADDR'];
        $ip = preg_replace('/[, ].*/', '', $ip);
        try {
            /* The deposit call is the main work horse here. It will issue a 
             * RPC call to Trustly and start a new payment. It will return an 
             * url to a page we should present to the end user and an orderid 
             * of the newly created order. See 
             * https://trustly.com/en/developer/documents for information about 
             * how the web page should be presented to the end user. 
             *
             * All of the parameters below are document in the API 
             * documentationf or the deposit call visit 
             * https://trustly.com/en/developer/api#/deposit for information on 
             * the specifics of all of the parameters. A few tips below.
             *
             * EndUserID - Make sure this is something unique per enduser in 
             * your system. In an e-commerce system the easiest unique per user 
             * identifier here will be the email address, make sure it is 
             * normalized if this field comes from raw user input. For an 
             * E-Wallet type solution this could be something like the customer 
             * id or similar.
             *
             * Amount/Currency - This is the amount of founds and in the 
             * currecny you are requesting with this call. All notifications on 
             * this order will normally be done in this currency. If the 
             * enduser will deposit money in e different currency we will make 
             * an fx of funds and you will be notified in the correct currency.
             *
             * ShopperStatement - This information will be visible on the end 
             * users account ledger for this deposit. Note that we are severely 
             * limited by the banks on what information we can relay to the end 
             * user. Some banks will only allow numbers, some banks will give 
             * us 5 characets while some banks nothing at all etc. We will make 
             * a best effort to relay your informaiton, keeping it as simple as 
             * possible will increase the chance of it looking as you would 
             * like.
             *
             * IntegrationModule - This is a field identifying the version of 
             * the software generating the request. This is for internal 
             * troubleshooting only. 
             */
            $deposit = $api->deposit("{$base_url}/php/example.php/notification", '*****@*****.**', $messageid, 'en_US', $amount, $currency, 'SE', NULL, NULL, NULL, NULL, 'Test', $ip, "{$base_url}/success.html", "{$base_url}/fail.html", NULL, "0", NULL, NULL, 'trustly-client-php example/1.0');
        } catch (Trustly_ConnectionException $e) {
            /* A connection exception can be the result if we are unable to 
             * establish a secure connection to the Trustly servers (failed to 
             * connect or failed to verify the server certificate for instance 
             * */
            respond_json(200, array('result' => 'error', 'error' => 'Trustly_ConnectionException ' . $a));
        } catch (Trustly_DataException $e) {
            /* A data exception will be thrown if we fail to properly sign the 
             * outgoing request, if the response does not seem related to our 
             * query or if the response data is not in the format we would 
             * expect */
            respond_json(200, array('result' => 'error', 'error' => 'Trustly_DataException ' . $a));
        } catch (Exception $e) {
            respond_json(200, array('result' => 'error', 'error' => 'Exception ' . $a));
        }
        if (isset($deposit)) {
            /* isSuccess() or isError() will reveal the outcome of the RPC call */
            if ($deposit->isSuccess()) {
                /* Using the getData() method you can access the individual 
                 * fields in the response from Trustly. Without arguments this 
                 * will return all of the data */
                $orderid = $deposit->getData('orderid');
                save_order_data($orderid, array('amount' => $amount, 'currency' => $currency, 'created' => @strftime('%F %T')));
                respond_json(200, array('result' => 'ok', 'url' => $deposit->getData('url'), 'orderid' => $orderid));
            } else {
                /* getErrorCode() and getErrorMessage() will reveal the problem 
                 * with the call. getErrorCode() will return an integer error 
                 * number identifying the problem at hand, use this for making 
                 * decisions on how to act. getErrorMessage() will return a 
                 * more descriptive text string with error information, this is 
                 * in a form for logging, not something to present to the end 
                 * user.
                 * */
                $errormessage = sprintf('Error: %s (%s)', $deposit->getErrorCode(), $deposit->getErrorMessage());
                respond_json(200, array('result' => 'error', 'error' => $errormessage));
            }
        }
    }
}