Skip to main content

Authentication

Introduction​

Moyasar's API uses API Keys to authenticate requests.

You can view and manage your API keys in the Moyasar Dashboard.

Publishable Key ​

Sending cardholder data to the merchant backend is prohibited and will result in canceling the agreement between Moyasar and the merchant in addition to the immediate termination of the service.

To address this issue, Moyasar has implemented a publishable API key, enabling merchants to initiate payments directly from the frontend or to tokenize card payments for later use in the merchant's backend.

The publishable API key is restricted to a single operation only:

  • Create Payment

With this restriction, this API key is safe to be shipped into client code like browsers and mobile apps.

Secret Key​

The secret API key allows you to perform all operations related to your account.

Unlike the publishable API key, the secret API key must be secret and only used from the merchant backend code.

Rotate your secret key regularly. When you do, you can keep the old key working for a short overlap so your servers switch to the new key without downtime. See Rotate your secret key.

If for any reason this key is leaked, regenerate it right away from Settings > API Keys in the Moyasar Dashboard and choose Stop it immediately, so the leaked key stops working at once.

info

For improved security, secret keys are now only partially visible in the dashboard. If you lose a key, you’ll need to regenerate it and store it securely. New keys are shown only once. Only secret key ID (which starts with sk_test_ or sk_live_) will remain visible and copyable.

Sandbox Environment

Moyasar provides a sandbox environment for testing purposes. Using the test mode doesn't affect your live data or interact with the banking networks. This allows you to test your integration and ensure everything is working correctly before going live with actual payments.

Test API keys are prefixed with the following keywords:

  • pk_test_
  • sk_test_

Live API keys on the other hand are prefixed with the following keywords:

  • pk_live_
  • sk_live_

Basic Auth

Authentication to the API is performed via HTTP Basic Auth.

You should send the Basic authentication scheme with the following fields:

  • Username: <your_api_key>
  • Password: <EMPTY>
Important

The password must be kept empty

HTTPS​

All API calls must be made over HTTPS; any API call made over HTTP will be rejected.

Example​

Here is an example of the List Payments endpoint in different programming languages

require 'vendor/autoload.php'; // Make sure Guzzle is installed via Composer

use GuzzleHttp\Client;

$client = new Client();

$response = $client->get('https://api.moyasar.com/v1/payments', [
'auth' => ['sk_test_123', ''],
]);

echo $response->getBody()->getContents();
tip

You must replace sk_test_123 with your API key.