From fe824a67d91135edee90b2fc51855be372154bec Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Mon, 11 Jul 2016 15:20:52 +0200 Subject: [PATCH 01/16] nettelerapi -> netellerapi --- composer.json | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index e597929..1a48e67 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,17 @@ { - "name": "geosub/nettelerapi", + "name": "petski/netellerapi", "description": "Neteller API", "type": "library", - "authors": [{ - "name": "Omnipay", - "email": "geosub@gmail.com" - }], + "authors": [ + { + "name": "Omnipay", + "email": "geosub@gmail.com" + }, + { + "name": "Patrick Kuijvenhoven", + "email": "patrick.kuijvenhoven@gmail.com" + } + ], "keywords": [ "omnipay", "neteller", "api", "php", "payment" ], "require": { "php": ">=5.4.0" From 478b9a7173399446bac735fa1137deedd8277a2b Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Mon, 11 Jul 2016 15:25:41 +0200 Subject: [PATCH 02/16] Namespace everything --- composer.json | 4 +--- lib/NetellerAPI.php | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 1a48e67..36dafcc 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,6 @@ "php": ">=5.4.0" }, "autoload": { - "classmap" : [ - "lib/NetellerAPI.php" - ] + "psr-4": { "NetellerAPI\\": "lib" } } } diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index f4bcfcc..75a3bb8 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -1,5 +1,7 @@ \ No newline at end of file +?> From 1a0c50d88607ba8270b109aa26ffb7d3bd2477ac Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Mon, 11 Jul 2016 17:18:18 +0200 Subject: [PATCH 03/16] Hooray for league/html-to-markdown --- NetellerAPI.html | 870 ----------------------------------------------- NetellerAPI.md | 735 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 735 insertions(+), 870 deletions(-) delete mode 100644 NetellerAPI.html create mode 100644 NetellerAPI.md diff --git a/NetellerAPI.html b/NetellerAPI.html deleted file mode 100644 index 9b1cf44..0000000 --- a/NetellerAPI.html +++ /dev/null @@ -1,870 +0,0 @@ - - - -NetellerAPI - - - - -

NETELLER REST API PHP Library

-

Introduction

-

The NETELLER PHP Library provides PHP developers an easy way to integrate the NETELLER REST API. It is a client library which provides PHP classes that correspond to resources in the NETELLER REST API.

- -

Installation

-

Simply download and include the "NetellerAPI.php" file in your script.

-
include_once("NetellerAPI.php");
-
- -

Configuration

-

You need to define the configuration details using the following PHP constants:

-
    -
  • NETELLER_BASE_URL - should contain the relevant REST API endpoint depending on whether you are using the sandbox or live environment.
  • -
  • NETELLER_CLIENT_ID - should contain the Client ID from the merchant account App.
  • -
  • NETELLER_CLIENT_SECRET - should contain the Client Secret from the merchant account App.
  • -
-

Example:

-
define('NETELLER_BASE_URL', 'https://test.api.neteller.com/');
-define('NETELLER_CLIENT_ID', 'AAABTAiQ9pKruN2Z');
-define('NETELLER_CLIENT_SECRET', '0.iSLQ7zzMinac6SbI62onxTdqEYFES1LXoI4paRFFz74.4yFz4Pr3BMIccXgQOb3Ea_FNG2Y');
-
- -

NetellerAPI Class

-

A parent class which all classes below extend.

-

Methods

-
    -
  • getIP() - Returns the outgoing IP address of the server where the script is hosted using an external service. Useful for debugging the "invalid_client" API error.
  • -
  • getUrl(string $url) - Executes a GET request to a URL from the NETELLER API and returns the result. Useful when implementing webhooks.
  • -
  • getToken_ClientCredentials() - Returns a new access token - "client_credentials" grant type.
  • -
  • getToken_AuthCode(string $authCode, string $redirectUri) - Returns a new access token - "auth_code" grant type.
  • -
  • getToken_RefreshToken(string $refreshToken) - Returns a new access token using a refresh token.
  • -
-

Example

-
$api = new NetellerAPI();
-$ip = $api->getIP();
-var_dump($ip);
-
- -

It can also be used in the context of a child class:

-
$deposit = new RequestPayment();
-$deposit->setPaymentMethodValue('netellertest_USD@neteller.com')
-        ->setVerificationCode(270955)
-        ->setTransactionMerchantRefId('adfiu1i23478172349a')
-        ->setTransactionAmount(1234)
-        ->setTransactionCurrency('USD');
-$result = $deposit->doRequest();
-$ip = $deposit->getIP();
-
-var_dump($result);
-var_dump($ip);
-
- -

RequestPayment Class

-

Creates a new incoming transfer payment.

-

Methods

-
    -
  • setPaymentMethodValue(string $paymentMethod) - Sets the member's email or 12 digit NETELLER Account ID.
  • -
  • setVerificationCode(string $verificationCode) - Sets the member's Secure ID or Google Authenticator OTP.
  • -
  • setTransactionMerchantRefId(string $merchantRefId) - Sets the merchant reference ID.
  • -
  • setTransactionAmount(int $transactionAmount) - Sets the amount for the transaction.
  • -
  • setTransactionCurrency(string $transactionCurrency) - Sets the currency for the transaction.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$deposit = new RequestPayment();
-$deposit->setPaymentMethodValue('netellertest_USD@neteller.com')
-        ->setVerificationCode(270955)
-        ->setTransactionMerchantRefId('adfiu1i23478172349a')
-        ->setTransactionAmount(1234)
-        ->setTransactionCurrency('USD');
-$result = $deposit->doRequest();
-var_dump($result);
-
- -

CreatePayment Class

-

Creates a new outgoing payment.

-

Methods

-
    -
  • setPayeeProfileEmail(string $payeeProfileEmail) - Sets the email of the member receiving the payment.
  • -
  • setTransactionAmount(int $transactionAmount) - Sets the amount for the transaction.
  • -
  • setTransactionCurrency(string $transactionCurrency) - Sets the currency for the transaction.
  • -
  • setTransactionMerchantRefId(string $transactionMerchantRefId) - Sets the merchant reference ID.
  • -
  • setMessage(string $message) - Sets the message that will be shown to the member notifying them of the pending transfer.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$withdrawal = new CreatePayment();
-$withdrawal->setPayeeProfileEmail('netellertest_USD@neteller.com')
-           ->setTransactionAmount(1234)
-           ->setTransactionCurrency('USD')
-           ->setTransactionMerchantRefId('adfiu1i23478172349W2')
-           ->setMessage('sample message');
-$result = $withdrawal->doRequest();
-var_dump($result);
-
- -

LookupPayment Class

-

Returns details about a previous payment request.

-

Methods

-
    -
  • setTransactionId(string $transactionId) - Sets the NETELLER transaction ID of the transaction you want to look up. You can either use this method or use "setMerchantRefId".
  • -
  • setMerchantRefId(string $merchantRefId) - Sets the merchant reference ID of the transaction you want to look up. You can either use this method or use "setTransactionId".
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupPayment();
-$lookup->setTransactionId('850430740226289')
-       ->setExpand('customer');
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

CreateOrder Class

-

Creates a payment order for NETELLERgo! You will need to redirect your customer to the returned URL to initiate the hosted Quick Checkout flow and collect the payment.

-

Methods

-
    -
  • setOrderMerchantRefId(string $orderMerchantRefId) - Sets the merchant reference ID.
  • -
  • setOrderTotalAmount(int $orderTotalAmount) - Sets the total amount for the order.
  • -
  • setOrderCurrency(string $orderCurrency) - Sets the currency for the order.
  • -
  • setOrderLang(string $orderLang) - Sets the language of the hosted payment page.
  • -
  • setOrderCustomerIp(string $orderCustomerIp) - Sets the IP address of the customer.
  • -
  • setItems(array $item) - Sets the item you are requesting payment for.
  • -
  • setFees(array $fee) - Sets the fee for this order.
  • -
  • setTaxes(array $tax) - Sets the tax for this order.
  • -
  • setPaymentMethods(array $paymentMethod) - sets the allowed payment methods for this order.
  • -
  • setRedirectOnSuccess(string $url) - Sets the success redirect URL.
  • -
  • setRedirectOnCancel(string $url) - Sets the cancel redirect URL.
  • -
  • setBillingDetailsEmail(string $billingDetailsEmail) - Sets the email address of the customer.
  • -
  • setBillingDetailsCountry(string $billingDetailsCountry) - Sets the country of residence of the customer (ISO 3166-1 Alpha 2-code)
  • -
  • setBillingDetailsFirstName(string $billingDetailsFirstName) - Sets the First Name of the customer.
  • -
  • setBillingDetailsLastName(string $billingDetailsLastName) - Sets the Last Name of the customer.
  • -
  • setBillingDetailsCity(string $billingDetailsCity) - Sets the city of residence of the customer.
  • -
  • setBillingDetailsAddress1(string $billingDetailsAddress1) - Sets the address (line 1) of the customer.
  • -
  • setBillingDetailsAddress2(string $billingDetailsAddress2) - Sets the address (line 2) of the customer.
  • -
  • setBillingDetailsAddress3(string $billingDetailsAddress3) - Sets the address (line 3) of the customer.
  • -
  • setBillingDetailsCountrySubDivisionCode(string $countrySubDivisionCode) - Sets the country subdivision code of the customer. The ISO 3166-2 code indicating the state/province/district or other value denoting the clients country subdivision
  • -
  • setBillingDetailsPostCode(string $billingDetailsPostCode) - Sets the post code of the customer.
  • -
  • setBillingDetailsLang(string $billingDetailsLang) - Sets the preferred language of communication of the customer.
  • -
  • setAttributes(array $attribute) - Sets additional attributes for this order.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getRedirectUrl() - Returns the URL where the client needs to be redirected to complete the payment.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$order = new CreateOrder();
-$order->setOrderMerchantRefId('adfiu1i23478172349o1')
-      ->setOrderTotalAmount(2099)
-      ->setOrderCurrency('USD')
-      ->setOrderLang('en_US')
-      ->setItems(array
-                    (
-                        "quantity" => 1,
-                        "name" => "Item A",
-                        "description" => "Lorem ipsum dolor sit amet",
-                        "sku" => "XYZPART1",
-                        "amount" => 1000
-                    )
-                )
-      ->setItems(array
-                    (
-                        "quantity" => 2,
-                        "name" => "Item B",
-                        "description" => "Consectetur adipiscing elit",
-                        "sku" => "XYZPART2",
-                        "amount" => 200
-                    )
-                )
-      ->setFees(array
-                    (
-                        "feeName" => "Setup Fee",
-                        "feeAmount" => 500
-                    )
-                )
-      ->setTaxes(array
-                    (
-                        "taxName" => "VAT",
-                        "taxAmount" => 199
-                    )
-                )
-      ->setPaymentMethods(array
-                (
-                    "type" => "onlinebanking",
-                    "value" => "sofortbanking"
-                )
-            )
-      ->setRedirectOnSuccess("https://example.com/success.html")
-      ->setRedirectOnCancel("https://example.com/cancel.html")
-      ->setBillingDetailsEmail("netellertest_USD@neteller.com")
-      ->setBillingDetailsCountry("DE")
-      ->setBillingDetailsFirstName("John")
-      ->setBillingDetailsLastName("Smith")
-      ->setBillingDetailsCity("Calgary")
-      ->setBillingDetailsAddress1("address line 1")
-      ->setBillingDetailsAddress2("address line 2")
-      ->setBillingDetailsAddress3("address line 3")
-      ->setBillingDetailsCountrySubDivisionCode("AB")
-      ->setBillingDetailsPostCode("T8A22J")
-      ->setBillingDetailsLang("en");
-$result = $order->doRequest();
-$redirectUrl = $order->getRedirectUrl();
-var_dump($result);
-var_dump($redirectUrl);
-
- -

LookupOrder Class

-

Returns details about a previous order request.

-

Methods

-
    -
  • setOrderId(string $orderId) - Sets the order ID.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupOrder();
-$lookup->setOrderId("ORD_1f21ca9d-e647-46bc-9dde-91c70632e587");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

LookupOrderInvoice Class

-

Returns details about an invoice for an order.

-

Methods

-
    -
  • setOrderId(string $orderId) - Sets the order ID.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupOrderInvoice();
-$lookup->setOrderId("ORD_5c0023d3-c928-4771-9016-1fc169283b0f")
-       ->setExpand("customer,order");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

CreateCustomer Class

-

Pre-populate the NETELLER sign-up page with information from your database, so you can speed up the registration process.

-

Methods

-
    -
  • setEmail(string $email) - Sets the email of the customer.
  • -
  • setFirstName(string $firstName) - Sets the first name of the customer.
  • -
  • setLastName(string $lastName) - Sets the last name of the customer.
  • -
  • setAddress1(string $address1) - Sets the address line 1 of the customer.
  • -
  • setAddress2(string $address2) - Sets the address line 2 of the customer.
  • -
  • setAddress3(string $address3) - Sets the address line 3 of the customer.
  • -
  • setCity(string $city) - Sets the city of the customer.
  • -
  • setCountry(string $country) - Sets the country of the customer. ISO 3166-1 Alpha 2-code.
  • -
  • setCountrySubDivisionCode(string $countrySubDivisionCode) - Sets the state/province of the customer. ISO 3166-2 code.
  • -
  • setPostCode(string $postCode) - Sets the post code of the customer.
  • -
  • setGender(string $gender) - Sets the gender of the customer.
  • -
  • setDobDay(string $dobDay) - Sets the date of birth day of the customer.
  • -
  • setDobMonth(string $dobMonth) - Sets the date of birth month of the customer.
  • -
  • setDobYear(string $dobYear) - Sets the date of birth year of the customer.
  • -
  • setLanguage(string $language) - Sets the preferred language of the customer.
  • -
  • setCurrency(string $currency) - Sets the preferred currency of the customer.
  • -
  • setMobile(string $mobile) - Sets the mobile phone of the customer.
  • -
  • setLandLine(string $landLine) - Sets the land line phone of the customer.
  • -
  • setBtag(string $btag) - sets the btag, used for affiliate tracking.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getRedirectUrl() - Returns the URL where the client needs to be redirected to complete the sign-up.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$signup = new CreateCustomer();
-$signup->setEmail("john.smith@example.com")
-       ->setFirstName("John")
-       ->setLastName("Smith")
-       ->setAddress1("address line 1")
-       ->setAddress2("address line 2")
-       ->setAddress3("address line 3")
-       ->setCity("Calgary")
-       ->setCountry("CA")
-       ->setCountrySubDivisionCode("AB")
-       ->setPostCode("T8A22J")
-       ->setGender("m")
-       ->setDobDay("31")
-       ->setDobMonth("01")
-       ->setDobYear("1975")
-       ->setLanguage("en_US")
-       ->setCurrency("EUR")
-       ->setMobile("14035552333")
-       ->setLandLine("14032332333")
-       ->setLinkBackUrl("https://example.com/")
-       ->setBtag("A_234B_345C_");
-$response = $signup->doRequest();
-$redirectUrl = $signup->getRedirectUrl();
-var_dump($response);
-var_dump($redirectUrl);
-
- -

LookupCustomer Class

-

Lookup details for a specific customer.

-

Methods

-
    -
  • setAccountId(string $accountId) - Sets the account ID of the customer. You can either use this method or "setCustomerId" and "setEmail".
  • -
  • setCustomerId(string $customerId) - Sets the customer ID of the customer. You can either use this method or "setAccountId" and "setEmail".
  • -
  • setEmail(string $email) - Sets the email of the customer. You can either use this method or "setAccountId" and "setCustomerId".
  • -
  • setRefreshToken(string $refreshToken) - Sets the refresh token to be used in order to obtain an access token. You can either use this method or use "setAuthCode". This method is used only when you want to receive customer data outside of the default scope.
  • -
  • setAuthCode(string $authCode) - Sets the authentication code to be used in order to obtain an access token. You can either use this method or use "setRefreshToken". This method is used only when you want to receive customer data outside of the default scope.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupCustomer();
-$lookup->setCustomerId("453523712313")
-       ->setRefreshToken("0.AgAAAU0yy4sHAAAAB1jwsOC9J7TBAYynTble-g2fdC-d.7xIAyXxQWsDaiLzjY4qimsqfyYU");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

CreatePlan Class

-

Creates a subscription plan.

-

Methods

-
    -
  • setPlanId(string $planId) - Sets the unique ID for the plan.
  • -
  • setPlanName(string $planName) - Sets the name of the plan.
  • -
  • setInterval(int $interval) - Sets the number of intervals between each billing attempt.
  • -
  • setIntervalType(string $intervalType) - Sets the frequency at which the plan subscriber will be billed (daily, weekly, monthly, yearly).
  • -
  • setIntervalCount(int $intervalCount) - Sets the length of the contract in intervals.
  • -
  • setAmount(int $amount) - Sets the amount to bill for each recurring payment.
  • -
  • setCurrency(string $currency) - Sets the currency in which the customer will be billed.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$plan = new CreatePlan();
-$plan->setPlanId("MONTHLYGREENPLAN")
-     ->setPlanName("Sample Premier Monthly Membership")
-     ->setInterval(3)
-     ->setIntervalType("monthly")
-     ->setIntervalCount(4)
-     ->setAmount(2995)
-     ->setCurrency("USD");
-$result = $plan->doRequest();
-var_dump($result);
-
- -

LookupPlan Class

-

Returns details about a previously created subscription plan.

-

Methods

-
    -
  • setPlanId(string $planId) - Sets the plan ID.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupPlan();
-$lookup->setPlanId("MONTHLYGREENPLAN");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

CancelPlan Class

-

Cancels a previously created subscription plan.

-

Methods

-
    -
  • setPlanId(string $planId) - Sets the plan ID.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$plan = new CancelPlan();
-$plan->setPlanId("MONTHLYGREENPLAN");
-$result = $plan->doRequest();
-var_dump($result);
-
- -

Delete Plan

-

Deletes a previously created subscription plan.

-

Methods

-
    -
  • setPlanId(string $planId) - Sets the plan ID.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$plan = new DeletePlan();
-$plan->setPlanId("MONTHLYGREENPLAN");
-$result = $plan->doRequest();
-var_dump($result);
-
- -

ListPlans Class

-

Returns a list of all plans.

-

Methods

-
    -
  • setLimit(int $limit) - Sets the number of records to be returned.
  • -
  • setOffset(int $offset) - Sets the results offset.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$plans = new ListPlans();
-$plans->setLimit(10)
-      ->setOffset(0);
-$result = $plans->doRequest();
-var_dump($result);
-
- -

CreateSubscription Class

-

Enrolls an existing NETELLER account holder in one of your subscription plans.

-

Methods

-
    -
  • setPlanId(string $planId) - Sets the plan ID.
  • -
  • setCustomerId(string $customerId) - Sets the Customer ID of the customer to be subscribed.
  • -
  • setStartDate(string $startDate) - Sets the start date for the subscription. The date needs to be in ISO 8601 format (UTC).
  • -
  • setRefreshToken(string $refreshToken) - Sets the refresh token to be used in order to obtain an access token. You can either use this method or use "setAuthCode".
  • -
  • setAuthCode(string $authCode) - Sets the authentication code to be used in order to obtain an access token. You can either use this method or use "setRefreshToken".
  • -
  • setRedirectUri(string $redirectUri) - Sets the redirect URI.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Examples

-

Using Authorization code

-
$subscription = new CreateSubscription();
-$subscription->setPlanId("MONTHLYGREENPLAN")
-             ->setAccountProfileEmail("netellertest_USD@neteller.com")
-             ->setStartDate("2015-05-09T00:00:00Z")
-             ->setAuthCode("0.AAAAAU0yjMR5AAAAAAAEk-B1A0yk5HA7RZkwz9zQYRFN.eNw8W12CqB06b2Qc2rvr3vUyc-g")
-             ->setRedirectUri("https://example.com/")
-             ->setExpand("plan,customer");
-$result = $subscription->doRequest();
-var_dump($result);
-
- -

Using Refresh token

-
$subscription = new CreateSubscription();
-$subscription->setPlanId("MONTHLYGREENPLAN")
-             ->setAccountProfileEmail("netellertest_USD@neteller.com")
-             ->setStartDate("2015-05-09T00:00:00Z")
-             ->setRefreshToken("0.AgAAAU0yy4sHAAAAB1jwsOC9J7TBAYynTble-g2fdC-d.7xIAyXxQWsDaiLzjY4qimsqfyYU")
-             ->setRedirectUri("https://example.com/")
-             ->setExpand("plan,customer");
-$result = $subscription->doRequest();
-var_dump($result);
-
- -

LookupSubscription Class

-

Returns details about a previously created subscription.

-

Methods

-
    -
  • setSubscriptionId(string $subscriptionId) - Sets the subscription ID.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupSubscription();
-$lookup->setSubscriptionId("180")
-       ->setExpand("plan,customer");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

CancelSubscription Class

-

Cancels a previously created subscription.

-

Methods

-
    -
  • setSubscriptionId(string $subscriptionId) - Sets the subscription ID.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$subscription = new CancelSubscription();
-$subscription->setSubscriptionId("181");
-$result = $subscription->doRequest();
-var_dump($result);
-
- -

ListSubscriptions Class

-

Lists all previously created subscriptions.

-

Methods

-
    -
  • setLimit(int $limit) - Sets the number of records to be returned.
  • -
  • setOffset(int $offset) - Sets the results offset.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$subscriptions = new ListSubscriptions();
-$subscriptions->setLimit(10)
-              ->setOffset(0);
-$result = $subscriptions->doRequest();
-var_dump($result);
-
- -

LookupSubscriptionInvoice Class

-

Looks up a subscription invoice.

-

Methods

-
    -
  • setSubscriptionId(string $subscriptionId) - Sets the subscription ID.
  • -
  • setInvoiceNumber(int $invoiceNumber) - Sets the invoice number.
  • -
  • setExpand(string $expandObjects) - A list of comma-separated names of objects to be expanded in the NETELLER REST API response.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupSubscriptionInvoice();
-$lookup->setSubscriptionId(166)
-       ->setInvoiceNumber(42)
-       ->setExpand("customer, subscription");
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

LookupAllSubscriptionInvoices Class

-

Looks up all subscription invoices.

-

Methods

-
    -
  • setSubscriptionId(string $subscriptionId) - Sets the subscription ID.
  • -
  • setLimit(int $limit) - Sets the number of records to be returned.
  • -
  • setOffset(int $offset) - Sets the results offset.
  • -
  • doRequest() - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred.
  • -
  • getExecutionErrors() - Returns an array with the error(s) returned by the NETELLER REST API.
  • -
-

Example

-
$lookup = new LookupAllSubscriptionInvoices();
-$lookup->setSubscriptionId(166)
-       ->setLimit(10)
-       ->setOffset(0);
-$result = $lookup->doRequest();
-var_dump($result);
-
- -

WebhookHandler Class

-

Handles incoming webhook requests.

-

Methods

-
    -
  • handleRequest() - Receives the webhook request and calls a callback function passing through the webhook data. You need to give the callback function(s) the same name as the webhook(s) you are subscribed to. Please refer to the REST API Guide for a list of all webhook names.
  • -
-

Example

-
$webhook = new WebhookHandler();
-$webhook->handleRequest();
-
-function payment_succeeded($data){
-    $api = new NetellerAPI();
-    $result = $api->getUrl($data->links[0]->url);
-    //do something with the response here
-}
-
- - - - - diff --git a/NetellerAPI.md b/NetellerAPI.md new file mode 100644 index 0000000..0249096 --- /dev/null +++ b/NetellerAPI.md @@ -0,0 +1,735 @@ +NETELLER REST API PHP Library +============================= + +Introduction +------------ + +The NETELLER PHP Library provides PHP developers an easy way to integrate the NETELLER REST API. It is a client library which provides PHP classes that correspond to resources in the NETELLER REST API. + +- [Installation](#Installation) +- [Configuration](#Configuration) +- [NetellerAPI Class](#NetellerAPI) +- [RequestPayment Class](#requestPayment) +- [CreatePayment Class](#CreatePayment) +- [LookupPayment Class](#LookupPayment) +- [CreateOrder Class](#CreateOrder) +- [LookupOrder Class](#LookupOrder) +- [LookupOrderInvoice Class](#LookupOrderInvoice) +- [CreateCustomer Class](#CreateCustomer) +- [LookupCustomer Class](#LookupCustomer) +- [CreatePlan Class](#CreatePlan) +- [LookupPlan Class](#LookupPlan) +- [CancelPlan Class](#CancelPlan) +- [DeletePlan Class](#DeletePlan) +- [ListPlans Class](#ListPlans) +- [CreateSubscription Class](#CreateSubscription) +- [LookupSubscription Class](#LookupSubscription) +- [CancelSubscription Class](#CancelSubscription) +- [ListSubscriptions Class](#ListSubscriptions) +- [LookupSubscriptionInvoice Class](#LookupSubscriptionInvoice) +- [LookupAllSubscriptionInvoices Class](#LookupAllSubscriptionInvoices) +- [WebhookHandler Class](#WebhookHandler) + +Installation +======================================== + +Simply download and include the "NetellerAPI.php" file in your script. + + + include_once("NetellerAPI.php"); + + +Configuration +========================================== + +You need to define the configuration details using the following PHP constants: + +- **NETELLER\_BASE\_URL** - should contain the relevant REST API endpoint depending on whether you are using the sandbox or live environment. +- **NETELLER\_CLIENT\_ID** - should contain the Client ID from the merchant account App. +- **NETELLER\_CLIENT\_SECRET** - should contain the Client Secret from the merchant account App. + +Example: + + + define('NETELLER_BASE_URL', 'https://test.api.neteller.com/'); + define('NETELLER_CLIENT_ID', 'AAABTAiQ9pKruN2Z'); + define('NETELLER_CLIENT_SECRET', '0.iSLQ7zzMinac6SbI62onxTdqEYFES1LXoI4paRFFz74.4yFz4Pr3BMIccXgQOb3Ea_FNG2Y'); + + +NetellerAPI Class +============================================ + +A parent class which all classes below extend. + +Methods +------- + +- **getIP()** - Returns the outgoing IP address of the server where the script is hosted using an external service. Useful for debugging the "invalid\_client" API error. +- **getUrl(string $url)** - Executes a GET request to a URL from the NETELLER API and returns the result. Useful when implementing webhooks. +- **getToken\_ClientCredentials()** - Returns a new access token - "client\_credentials" grant type. +- **getToken\_AuthCode(string $authCode, string $redirectUri)** - Returns a new access token - "auth\_code" grant type. +- **getToken\_RefreshToken(string $refreshToken)** - Returns a new access token using a refresh token. + +Example +------- + + + $api = new NetellerAPI(); + $ip = $api->getIP(); + var_dump($ip); + + +It can also be used in the context of a child class: + + + $deposit = new RequestPayment(); + $deposit->setPaymentMethodValue('netellertest_USD@neteller.com') + ->setVerificationCode(270955) + ->setTransactionMerchantRefId('adfiu1i23478172349a') + ->setTransactionAmount(1234) + ->setTransactionCurrency('USD'); + $result = $deposit->doRequest(); + $ip = $deposit->getIP(); + + var_dump($result); + var_dump($ip); + + +RequestPayment Class +================================================== + +Creates a new incoming transfer payment. + +Methods +------- + +- **setPaymentMethodValue(string $paymentMethod)** - Sets the member's email or 12 digit NETELLER Account ID. +- **setVerificationCode(string $verificationCode)** - Sets the member's Secure ID or Google Authenticator OTP. +- **setTransactionMerchantRefId(string $merchantRefId)** - Sets the merchant reference ID. +- **setTransactionAmount(int $transactionAmount)** - Sets the amount for the transaction. +- **setTransactionCurrency(string $transactionCurrency)** - Sets the currency for the transaction. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $deposit = new RequestPayment(); + $deposit->setPaymentMethodValue('netellertest_USD@neteller.com') + ->setVerificationCode(270955) + ->setTransactionMerchantRefId('adfiu1i23478172349a') + ->setTransactionAmount(1234) + ->setTransactionCurrency('USD'); + $result = $deposit->doRequest(); + var_dump($result); + + +CreatePayment Class +================================================ + +Creates a new outgoing payment. + +Methods +------- + +- **setPayeeProfileEmail(string $payeeProfileEmail)** - Sets the email of the member receiving the payment. +- **setTransactionAmount(int $transactionAmount)** - Sets the amount for the transaction. +- **setTransactionCurrency(string $transactionCurrency)** - Sets the currency for the transaction. +- **setTransactionMerchantRefId(string $transactionMerchantRefId)** - Sets the merchant reference ID. +- **setMessage(string $message)** - Sets the message that will be shown to the member notifying them of the pending transfer. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $withdrawal = new CreatePayment(); + $withdrawal->setPayeeProfileEmail('netellertest_USD@neteller.com') + ->setTransactionAmount(1234) + ->setTransactionCurrency('USD') + ->setTransactionMerchantRefId('adfiu1i23478172349W2') + ->setMessage('sample message'); + $result = $withdrawal->doRequest(); + var_dump($result); + + +LookupPayment Class +================================================ + +Returns details about a previous payment request. + +Methods +------- + +- **setTransactionId(string $transactionId)** - Sets the NETELLER transaction ID of the transaction you want to look up. You can either use this method or use "setMerchantRefId". +- **setMerchantRefId(string $merchantRefId)** - Sets the merchant reference ID of the transaction you want to look up. You can either use this method or use "setTransactionId". +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupPayment(); + $lookup->setTransactionId('850430740226289') + ->setExpand('customer'); + $result = $lookup->doRequest(); + var_dump($result); + + +CreateOrder Class +============================================ + +Creates a payment order for NETELLERgo! You will need to redirect your customer to the returned URL to initiate the hosted Quick Checkout flow and collect the payment. + +Methods +------- + +- **setOrderMerchantRefId(string $orderMerchantRefId)** - Sets the merchant reference ID. +- **setOrderTotalAmount(int $orderTotalAmount)** - Sets the total amount for the order. +- **setOrderCurrency(string $orderCurrency)** - Sets the currency for the order. +- **setOrderLang(string $orderLang)** - Sets the language of the hosted payment page. +- **setOrderCustomerIp(string $orderCustomerIp)** - Sets the IP address of the customer. +- **setItems(array $item)** - Sets the item you are requesting payment for. +- **setFees(array $fee)** - Sets the fee for this order. +- **setTaxes(array $tax)** - Sets the tax for this order. +- **setPaymentMethods(array $paymentMethod)** - sets the allowed payment methods for this order. +- **setRedirectOnSuccess(string $url)** - Sets the success redirect URL. +- **setRedirectOnCancel(string $url)** - Sets the cancel redirect URL. +- **setBillingDetailsEmail(string $billingDetailsEmail)** - Sets the email address of the customer. +- **setBillingDetailsCountry(string $billingDetailsCountry)** - Sets the country of residence of the customer (ISO 3166-1 Alpha 2-code) +- **setBillingDetailsFirstName(string $billingDetailsFirstName)** - Sets the First Name of the customer. +- **setBillingDetailsLastName(string $billingDetailsLastName)** - Sets the Last Name of the customer. +- **setBillingDetailsCity(string $billingDetailsCity)** - Sets the city of residence of the customer. +- **setBillingDetailsAddress1(string $billingDetailsAddress1)** - Sets the address (line 1) of the customer. +- **setBillingDetailsAddress2(string $billingDetailsAddress2)** - Sets the address (line 2) of the customer. +- **setBillingDetailsAddress3(string $billingDetailsAddress3)** - Sets the address (line 3) of the customer. +- **setBillingDetailsCountrySubDivisionCode(string $countrySubDivisionCode)** - Sets the country subdivision code of the customer. The ISO 3166-2 code indicating the state/province/district or other value denoting the clients country subdivision +- **setBillingDetailsPostCode(string $billingDetailsPostCode)** - Sets the post code of the customer. +- **setBillingDetailsLang(string $billingDetailsLang)** - Sets the preferred language of communication of the customer. +- **setAttributes(array $attribute)** - Sets additional attributes for this order. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getRedirectUrl()** - Returns the URL where the client needs to be redirected to complete the payment. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $order = new CreateOrder(); + $order->setOrderMerchantRefId('adfiu1i23478172349o1') + ->setOrderTotalAmount(2099) + ->setOrderCurrency('USD') + ->setOrderLang('en_US') + ->setItems(array + ( + "quantity" => 1, + "name" => "Item A", + "description" => "Lorem ipsum dolor sit amet", + "sku" => "XYZPART1", + "amount" => 1000 + ) + ) + ->setItems(array + ( + "quantity" => 2, + "name" => "Item B", + "description" => "Consectetur adipiscing elit", + "sku" => "XYZPART2", + "amount" => 200 + ) + ) + ->setFees(array + ( + "feeName" => "Setup Fee", + "feeAmount" => 500 + ) + ) + ->setTaxes(array + ( + "taxName" => "VAT", + "taxAmount" => 199 + ) + ) + ->setPaymentMethods(array + ( + "type" => "onlinebanking", + "value" => "sofortbanking" + ) + ) + ->setRedirectOnSuccess("https://example.com/success.html") + ->setRedirectOnCancel("https://example.com/cancel.html") + ->setBillingDetailsEmail("netellertest_USD@neteller.com") + ->setBillingDetailsCountry("DE") + ->setBillingDetailsFirstName("John") + ->setBillingDetailsLastName("Smith") + ->setBillingDetailsCity("Calgary") + ->setBillingDetailsAddress1("address line 1") + ->setBillingDetailsAddress2("address line 2") + ->setBillingDetailsAddress3("address line 3") + ->setBillingDetailsCountrySubDivisionCode("AB") + ->setBillingDetailsPostCode("T8A22J") + ->setBillingDetailsLang("en"); + $result = $order->doRequest(); + $redirectUrl = $order->getRedirectUrl(); + var_dump($result); + var_dump($redirectUrl); + + +LookupOrder Class +============================================ + +Returns details about a previous order request. + +Methods +------- + +- **setOrderId(string $orderId)** - Sets the order ID. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupOrder(); + $lookup->setOrderId("ORD_1f21ca9d-e647-46bc-9dde-91c70632e587"); + $result = $lookup->doRequest(); + var_dump($result); + + +LookupOrderInvoice Class +========================================================== + +Returns details about an invoice for an order. + +Methods +------- + +- **setOrderId(string $orderId)** - Sets the order ID. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupOrderInvoice(); + $lookup->setOrderId("ORD_5c0023d3-c928-4771-9016-1fc169283b0f") + ->setExpand("customer,order"); + $result = $lookup->doRequest(); + var_dump($result); + + +CreateCustomer Class +================================================== + +Pre-populate the NETELLER sign-up page with information from your database, so you can speed up the registration process. + +Methods +------- + +- **setEmail(string $email)** - Sets the email of the customer. +- **setFirstName(string $firstName)** - Sets the first name of the customer. +- **setLastName(string $lastName)** - Sets the last name of the customer. +- **setAddress1(string $address1)** - Sets the address line 1 of the customer. +- **setAddress2(string $address2)** - Sets the address line 2 of the customer. +- **setAddress3(string $address3)** - Sets the address line 3 of the customer. +- **setCity(string $city)** - Sets the city of the customer. +- **setCountry(string $country)** - Sets the country of the customer. ISO 3166-1 Alpha 2-code. +- **setCountrySubDivisionCode(string $countrySubDivisionCode)** - Sets the state/province of the customer. ISO 3166-2 code. +- **setPostCode(string $postCode)** - Sets the post code of the customer. +- **setGender(string $gender)** - Sets the gender of the customer. +- **setDobDay(string $dobDay)** - Sets the date of birth day of the customer. +- **setDobMonth(string $dobMonth)** - Sets the date of birth month of the customer. +- **setDobYear(string $dobYear)** - Sets the date of birth year of the customer. +- **setLanguage(string $language)** - Sets the preferred language of the customer. +- **setCurrency(string $currency)** - Sets the preferred currency of the customer. +- **setMobile(string $mobile)** - Sets the mobile phone of the customer. +- **setLandLine(string $landLine)** - Sets the land line phone of the customer. +- **setBtag(string $btag)** - sets the btag, used for affiliate tracking. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getRedirectUrl()** - Returns the URL where the client needs to be redirected to complete the sign-up. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $signup = new CreateCustomer(); + $signup->setEmail("john.smith@example.com") + ->setFirstName("John") + ->setLastName("Smith") + ->setAddress1("address line 1") + ->setAddress2("address line 2") + ->setAddress3("address line 3") + ->setCity("Calgary") + ->setCountry("CA") + ->setCountrySubDivisionCode("AB") + ->setPostCode("T8A22J") + ->setGender("m") + ->setDobDay("31") + ->setDobMonth("01") + ->setDobYear("1975") + ->setLanguage("en_US") + ->setCurrency("EUR") + ->setMobile("14035552333") + ->setLandLine("14032332333") + ->setLinkBackUrl("https://example.com/") + ->setBtag("A_234B_345C_"); + $response = $signup->doRequest(); + $redirectUrl = $signup->getRedirectUrl(); + var_dump($response); + var_dump($redirectUrl); + + +LookupCustomer Class +================================================== + +Lookup details for a specific customer. + +Methods +------- + +- **setAccountId(string $accountId)** - Sets the account ID of the customer. You can either use this method or "setCustomerId" and "setEmail". +- **setCustomerId(string $customerId)** - Sets the customer ID of the customer. You can either use this method or "setAccountId" and "setEmail". +- **setEmail(string $email)** - Sets the email of the customer. You can either use this method or "setAccountId" and "setCustomerId". +- **setRefreshToken(string $refreshToken)** - Sets the refresh token to be used in order to obtain an access token. You can either use this method or use "setAuthCode". This method is used only when you want to receive customer data outside of the default scope. +- **setAuthCode(string $authCode)** - Sets the authentication code to be used in order to obtain an access token. You can either use this method or use "setRefreshToken". This method is used only when you want to receive customer data outside of the default scope. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupCustomer(); + $lookup->setCustomerId("453523712313") + ->setRefreshToken("0.AgAAAU0yy4sHAAAAB1jwsOC9J7TBAYynTble-g2fdC-d.7xIAyXxQWsDaiLzjY4qimsqfyYU"); + $result = $lookup->doRequest(); + var_dump($result); + + +CreatePlan Class +========================================== + +Creates a subscription plan. + +Methods +------- + +- **setPlanId(string $planId)** - Sets the unique ID for the plan. +- **setPlanName(string $planName)** - Sets the name of the plan. +- **setInterval(int $interval)** - Sets the number of intervals between each billing attempt. +- **setIntervalType(string $intervalType)** - Sets the frequency at which the plan subscriber will be billed (daily, weekly, monthly, yearly). +- **setIntervalCount(int $intervalCount)** - Sets the length of the contract in intervals. +- **setAmount(int $amount)** - Sets the amount to bill for each recurring payment. +- **setCurrency(string $currency)** - Sets the currency in which the customer will be billed. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $plan = new CreatePlan(); + $plan->setPlanId("MONTHLYGREENPLAN") + ->setPlanName("Sample Premier Monthly Membership") + ->setInterval(3) + ->setIntervalType("monthly") + ->setIntervalCount(4) + ->setAmount(2995) + ->setCurrency("USD"); + $result = $plan->doRequest(); + var_dump($result); + + +LookupPlan Class +========================================== + +Returns details about a previously created subscription plan. + +Methods +------- + +- **setPlanId(string $planId)** - Sets the plan ID. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupPlan(); + $lookup->setPlanId("MONTHLYGREENPLAN"); + $result = $lookup->doRequest(); + var_dump($result); + + +CancelPlan Class +========================================== + +Cancels a previously created subscription plan. + +Methods +------- + +- **setPlanId(string $planId)** - Sets the plan ID. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $plan = new CancelPlan(); + $plan->setPlanId("MONTHLYGREENPLAN"); + $result = $plan->doRequest(); + var_dump($result); + + +Delete Plan +===================================== + +Deletes a previously created subscription plan. + +Methods +------- + +- **setPlanId(string $planId)** - Sets the plan ID. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $plan = new DeletePlan(); + $plan->setPlanId("MONTHLYGREENPLAN"); + $result = $plan->doRequest(); + var_dump($result); + + +ListPlans Class +======================================== + +Returns a list of all plans. + +Methods +------- + +- **setLimit(int $limit)** - Sets the number of records to be returned. +- **setOffset(int $offset)** - Sets the results offset. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $plans = new ListPlans(); + $plans->setLimit(10) + ->setOffset(0); + $result = $plans->doRequest(); + var_dump($result); + + +CreateSubscription Class +========================================================== + +Enrolls an existing NETELLER account holder in one of your subscription plans. + +Methods +------- + +- **setPlanId(string $planId)** - Sets the plan ID. +- **setCustomerId(string $customerId)** - Sets the Customer ID of the customer to be subscribed. +- **setStartDate(string $startDate)** - Sets the start date for the subscription. The date needs to be in ISO 8601 format (UTC). +- **setRefreshToken(string $refreshToken)** - Sets the refresh token to be used in order to obtain an access token. You can either use this method or use "setAuthCode". +- **setAuthCode(string $authCode)** - Sets the authentication code to be used in order to obtain an access token. You can either use this method or use "setRefreshToken". +- **setRedirectUri(string $redirectUri)** - Sets the redirect URI. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Examples +-------- + +### Using Authorization code + + + $subscription = new CreateSubscription(); + $subscription->setPlanId("MONTHLYGREENPLAN") + ->setAccountProfileEmail("netellertest_USD@neteller.com") + ->setStartDate("2015-05-09T00:00:00Z") + ->setAuthCode("0.AAAAAU0yjMR5AAAAAAAEk-B1A0yk5HA7RZkwz9zQYRFN.eNw8W12CqB06b2Qc2rvr3vUyc-g") + ->setRedirectUri("https://example.com/") + ->setExpand("plan,customer"); + $result = $subscription->doRequest(); + var_dump($result); + + +### Using Refresh token + + + $subscription = new CreateSubscription(); + $subscription->setPlanId("MONTHLYGREENPLAN") + ->setAccountProfileEmail("netellertest_USD@neteller.com") + ->setStartDate("2015-05-09T00:00:00Z") + ->setRefreshToken("0.AgAAAU0yy4sHAAAAB1jwsOC9J7TBAYynTble-g2fdC-d.7xIAyXxQWsDaiLzjY4qimsqfyYU") + ->setRedirectUri("https://example.com/") + ->setExpand("plan,customer"); + $result = $subscription->doRequest(); + var_dump($result); + + +LookupSubscription Class +========================================================== + +Returns details about a previously created subscription. + +Methods +------- + +- **setSubscriptionId(string $subscriptionId)** - Sets the subscription ID. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupSubscription(); + $lookup->setSubscriptionId("180") + ->setExpand("plan,customer"); + $result = $lookup->doRequest(); + var_dump($result); + + +CancelSubscription Class +========================================================== + +Cancels a previously created subscription. + +Methods +------- + +- **setSubscriptionId(string $subscriptionId)** - Sets the subscription ID. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $subscription = new CancelSubscription(); + $subscription->setSubscriptionId("181"); + $result = $subscription->doRequest(); + var_dump($result); + + +ListSubscriptions Class +======================================================== + +Lists all previously created subscriptions. + +Methods +------- + +- **setLimit(int $limit)** - Sets the number of records to be returned. +- **setOffset(int $offset)** - Sets the results offset. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $subscriptions = new ListSubscriptions(); + $subscriptions->setLimit(10) + ->setOffset(0); + $result = $subscriptions->doRequest(); + var_dump($result); + + +LookupSubscriptionInvoice Class +======================================================================== + +Looks up a subscription invoice. + +Methods +------- + +- **setSubscriptionId(string $subscriptionId)** - Sets the subscription ID. +- **setInvoiceNumber(int $invoiceNumber)** - Sets the invoice number. +- **setExpand(string $expandObjects)** - A list of comma-separated names of objects to be expanded in the NETELLER REST API response. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupSubscriptionInvoice(); + $lookup->setSubscriptionId(166) + ->setInvoiceNumber(42) + ->setExpand("customer, subscription"); + $result = $lookup->doRequest(); + var_dump($result); + + +LookupAllSubscriptionInvoices Class +================================================================================ + +Looks up all subscription invoices. + +Methods +------- + +- **setSubscriptionId(string $subscriptionId)** - Sets the subscription ID. +- **setLimit(int $limit)** - Sets the number of records to be returned. +- **setOffset(int $offset)** - Sets the results offset. +- **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. + +Example +------- + + + $lookup = new LookupAllSubscriptionInvoices(); + $lookup->setSubscriptionId(166) + ->setLimit(10) + ->setOffset(0); + $result = $lookup->doRequest(); + var_dump($result); + + +WebhookHandler Class +================================================== + +Handles incoming webhook requests. + +Methods +------- + +- **handleRequest()** - Receives the webhook request and calls a callback function passing through the webhook data. You need to give the callback function(s) the same name as the webhook(s) you are subscribed to. Please refer to the REST API Guide for a list of all webhook names. + +Example +------- + + + $webhook = new WebhookHandler(); + $webhook->handleRequest(); + + function payment_succeeded($data){ + $api = new NetellerAPI(); + $result = $api->getUrl($data->links[0]->url); + //do something with the response here + } From 40a12b35d9cffe224291a00f3beb8a6f5ebf50d6 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Mon, 11 Jul 2016 17:19:24 +0200 Subject: [PATCH 04/16] Name documentation README.md, github's default --- NetellerAPI.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename NetellerAPI.md => README.md (100%) diff --git a/NetellerAPI.md b/README.md similarity index 100% rename from NetellerAPI.md rename to README.md From d26f1163c892a0ff1c14f63e00a389f7d37ba4f9 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Mon, 11 Jul 2016 17:35:05 +0200 Subject: [PATCH 05/16] Don't be CURLOPT_VERBOSE --- lib/NetellerAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index 75a3bb8..5fc9e5a 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -186,7 +186,7 @@ protected function makeHttpRequest($method, $path, $queryParams = array(), $head //return the response headers curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_VERBOSE, true); + // curl_setopt($ch, CURLOPT_VERBOSE, true); //method && request params: switch (strtolower($method)) From 271e56e188459d60b5841e52f89306e7b427bed3 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Tue, 12 Jul 2016 13:52:26 +0200 Subject: [PATCH 06/16] Improved executionErrors() logic --- README.md | 1 + lib/NetellerAPI.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0249096..7ab21bd 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Methods - **getToken\_ClientCredentials()** - Returns a new access token - "client\_credentials" grant type. - **getToken\_AuthCode(string $authCode, string $redirectUri)** - Returns a new access token - "auth\_code" grant type. - **getToken\_RefreshToken(string $refreshToken)** - Returns a new access token using a refresh token. +- **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. Example ------- diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index 5fc9e5a..6a418f4 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -6,6 +6,7 @@ class NetellerAPI{ var $baseUrl; var $clientId; var $clientSecret; + var $executionErrors = array(); public function __construct(){ $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); @@ -55,6 +56,7 @@ public function getUrl($url){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -90,6 +92,7 @@ public function getToken_ClientCredentials(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody->accessToken; } elseif($responseInfo['http_code'] >= 400){ @@ -123,6 +126,7 @@ public function getToken_AuthCode($authCode, $redirectUri){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody->accessToken; } elseif($responseInfo['http_code'] >= 400){ @@ -157,6 +161,7 @@ public function getToken_RefreshToken($refreshToken){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody->accessToken; } elseif($responseInfo['http_code'] >= 400){ @@ -261,6 +266,10 @@ protected function makeHttpRequest($method, $path, $queryParams = array(), $head return $response; } + + public function getExecutionErrors(){ + return $this->executionErrors; + } } class RequestPayment extends NetellerAPI{ @@ -348,6 +357,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -452,6 +462,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -531,6 +542,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -802,7 +814,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ - + $this->executionErrors = array(); foreach($responseBody->links as $struct) { if ($struct->rel == "hosted_payment") { $this->redirectUrl = $struct->url; @@ -869,6 +881,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -936,6 +949,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1143,6 +1157,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); foreach($responseBody->links as $struct) { if ($struct->rel == "member_signup_redirect") { $this->redirectUrl = $struct->url; @@ -1260,6 +1275,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1362,6 +1378,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1418,6 +1435,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1474,6 +1492,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1530,6 +1549,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1595,6 +1615,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1707,6 +1728,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1775,6 +1797,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1831,6 +1854,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1897,6 +1921,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -1970,6 +1995,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ @@ -2043,6 +2069,7 @@ public function doRequest(){ $responseBody = json_decode($response['body']); if($responseInfo['http_code'] == 200){ + $this->executionErrors = array(); return $responseBody; } elseif($responseInfo['http_code'] >= 400){ From 2fc6d7d32f38d7b0c819dae33c68ddd42940e1e4 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 11:21:20 +0200 Subject: [PATCH 07/16] Fix URL --- lib/NetellerAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index 6a418f4..79c7a15 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -809,7 +809,7 @@ public function doRequest(){ $requestParams['billingDetails'][0]['lang'] = $this->billingDetailsLang; } - $response = $this->post("/v1/orders", $queryParams, $headers, $requestParams); + $response = $this->post("v1/orders", $queryParams, $headers, $requestParams); $responseInfo = $response['info']; $responseBody = json_decode($response['body']); From 7a4e35fd4d78cba1a08bcf2668cdbe52c94319ce Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 11:56:48 +0200 Subject: [PATCH 08/16] Don't send billingDetails if we don't have any --- lib/NetellerAPI.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index 79c7a15..f690274 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -809,6 +809,13 @@ public function doRequest(){ $requestParams['billingDetails'][0]['lang'] = $this->billingDetailsLang; } + # Don't send billingDetails if we don't have any + if(is_array($requestParams['billingDetails']) && count($requestParams['billingDetails']) == 1 && + array_key_exists(0, $requestParams['billingDetails']) && is_array($requestParams['billingDetails'][0]) && + count($requestParams['billingDetails'][0]) == 0) { + unset($requestParams['billingDetails']); + } + $response = $this->post("v1/orders", $queryParams, $headers, $requestParams); $responseInfo = $response['info']; $responseBody = json_decode($response['body']); From aa2b63de2a7d6b296e90a457c978e2d48b829fe7 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 12:58:21 +0200 Subject: [PATCH 09/16] Implement getOrderId --- README.md | 1 + lib/NetellerAPI.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 7ab21bd..6200dbf 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,7 @@ Methods - **setBillingDetailsLang(string $billingDetailsLang)** - Sets the preferred language of communication of the customer. - **setAttributes(array $attribute)** - Sets additional attributes for this order. - **doRequest()** - Executes the API request. Returns the JSON-decoded object of the NETELLER REST API response, or "(bool)false" if an error has occurred. +- **getOrderId()** - Returns the NETELLER order id or null (in case doRequest() not called yet, or error occurred) - **getRedirectUrl()** - Returns the URL where the client needs to be redirected to complete the payment. - **getExecutionErrors()** - Returns an array with the error(s) returned by the NETELLER REST API. diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index f690274..c9e1f28 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -565,6 +565,7 @@ public function getExecutionErrors(){ } class CreateOrder extends NetellerAPI{ + var $orderId; var $orderMerchantRefId; var $orderTotalAmount; var $orderCurrency; @@ -822,6 +823,7 @@ public function doRequest(){ if($responseInfo['http_code'] == 200){ $this->executionErrors = array(); + $this->orderId = $responseBody->orderId; foreach($responseBody->links as $struct) { if ($struct->rel == "hosted_payment") { $this->redirectUrl = $struct->url; @@ -831,6 +833,7 @@ public function doRequest(){ return $responseBody; } elseif($responseInfo['http_code'] >= 400){ + $this->orderId = null; $this->executionErrors = array( 'http_status_code' => $responseInfo['http_code'], 'api_error_code' => $responseBody->error->code, @@ -843,6 +846,10 @@ public function doRequest(){ return false; } } + + public function getOrderId() { + return $this->orderId; + } public function getRedirectUrl(){ return $this->redirectUrl; From 938406cb5ab0958d4ab297c2a6bced738babc425 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 13:10:05 +0200 Subject: [PATCH 10/16] Avoid using constants --- lib/NetellerAPI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index c9e1f28..fe404ec 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -40,7 +40,7 @@ public function getUrl($url){ return false; } - $path = str_replace(NETELLER_BASE_URL, "/", $url); + $path = str_replace($this->baseUrl, "/", $url); $queryParams = array(); @@ -85,7 +85,7 @@ public function getToken_ClientCredentials(){ $headers = array ( "Content-type" => "application/json", - "Authorization" => "Basic ". base64_encode( NETELLER_CLIENT_ID . ":" . NETELLER_CLIENT_SECRET) + "Authorization" => "Basic ". base64_encode( $this->clientId . ":" . $this->clientSecret ) ); $response = $this->post("v1/oauth2/token", $queryParams, $headers, array()); $responseInfo = $response['info']; @@ -119,7 +119,7 @@ public function getToken_AuthCode($authCode, $redirectUri){ $headers = array ( "Content-type" => "application/json", - "Authorization" => "Basic ". base64_encode( NETELLER_CLIENT_ID . ":" . NETELLER_CLIENT_SECRET) + "Authorization" => "Basic ". base64_encode( $this->clientId . ":" . $this->clientSecret ) ); $response = $this->post("v1/oauth2/token", $queryParams, $headers, array()); $responseInfo = $response['info']; @@ -153,7 +153,7 @@ public function getToken_RefreshToken($refreshToken){ $headers = array ( "Content-type" => "application/json", - "Authorization" => "Basic ". base64_encode( NETELLER_CLIENT_ID . ":" . NETELLER_CLIENT_SECRET) + "Authorization" => "Basic ". base64_encode( $this->clientId . ":" . $this->clientSecret ) ); $response = $this->post("v1/oauth2/token", $queryParams, $headers, array()); From edac99b9bdca8978d455a787eb31b0686d92f734 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 13:47:44 +0200 Subject: [PATCH 11/16] Ability to give required variables to the constructor instead --- lib/NetellerAPI.php | 85 ++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index fe404ec..e2e965f 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -8,8 +8,13 @@ class NetellerAPI{ var $clientSecret; var $executionErrors = array(); - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + foreach(array('NETELLER_BASE_URL','NETELLER_CLIENT_ID','NETELLER_CLIENT_SECRET') as $constant) { + if(! array_key_exists($constant, $opts) || empty($opts[$constant])) { + $opts[$constant] = constant($constant); + } + } + $this->setApiCredentials($opts['NETELLER_BASE_URL'], $opts['NETELLER_CLIENT_ID'], $opts['NETELLER_CLIENT_SECRET']); } public function getIP(){ @@ -282,8 +287,8 @@ class RequestPayment extends NetellerAPI{ var $expandObjects; var $executionErrors = array(); - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPaymentMethodValue($paymentMethodValue){ @@ -389,8 +394,8 @@ class CreatePayment extends NetellerAPI{ var $executionErrors = array(); - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPayeeProfileEmail($payeeProfileEmail){ @@ -491,8 +496,8 @@ class LookupPayment extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setTransactionId($transactionId){ @@ -593,8 +598,8 @@ class CreateOrder extends NetellerAPI{ var $redirectUrl; var $executionErrors = array(); - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setOrderMerchantRefId($orderMerchantRefId){ @@ -865,8 +870,8 @@ class LookupOrder extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setOrderId($orderId){ @@ -923,8 +928,8 @@ class LookupOrderInvoice extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setOrderId($orderId){ @@ -1007,8 +1012,8 @@ class CreateCustomer extends NetellerAPI{ var $redirectUrl; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setEmail($email){ @@ -1212,8 +1217,8 @@ class LookupCustomer extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setAccountId($accountId){ @@ -1322,8 +1327,8 @@ class CreatePlan extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPlanId($planId){ @@ -1419,8 +1424,8 @@ class LookupPlan extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPlanId($planId){ @@ -1476,8 +1481,8 @@ class CancelPlan extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPlanId($planId){ @@ -1533,8 +1538,8 @@ class DeletePlan extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPlanId($planId){ @@ -1590,8 +1595,8 @@ class ListPlans extends NetellerAPI{ var $limit; var $offset; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setLimit($limit){ @@ -1663,8 +1668,8 @@ class CreateSubscription extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setPlanId($planId){ @@ -1770,8 +1775,8 @@ class LookupSubscription extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setSubscriptionId($subscriptionId){ @@ -1838,8 +1843,8 @@ class CancelSubscription extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setSubscriptionId($subscriptionId){ @@ -1896,8 +1901,8 @@ class ListSubscriptions extends NetellerAPI{ var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setLimit($limit){ @@ -1964,8 +1969,8 @@ class LookupSubscriptionInvoice extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setSubscriptionId($subscriptionId){ @@ -2039,8 +2044,8 @@ class LookupAllSubscriptionInvoices extends NetellerAPI{ var $expandObjects; var $executionErrors; - public function __construct(){ - $this->setApiCredentials(NETELLER_BASE_URL,NETELLER_CLIENT_ID,NETELLER_CLIENT_SECRET); + public function __construct(array $opts = array()){ + return parent::__construct($opts); } public function setSubscriptionId($subscriptionId){ From aa114f780d95927d1d5167a9cb13ca9682ec31e4 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 13:53:47 +0200 Subject: [PATCH 12/16] Minor documentation update --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 6200dbf..bc148ad 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ Example: define('NETELLER_CLIENT_ID', 'AAABTAiQ9pKruN2Z'); define('NETELLER_CLIENT_SECRET', '0.iSLQ7zzMinac6SbI62onxTdqEYFES1LXoI4paRFFz74.4yFz4Pr3BMIccXgQOb3Ea_FNG2Y'); +Alternatively, you may pass these required parameters to the constructor of each method instead: + + $deposit = new RequestPayment(array( + 'NETELLER_BASE_URL' => 'https://test.api.neteller.com/', + 'NETELLER_CLIENT_ID' => 'AAABTAiQ9pKruN2Z', + 'NETELLER_CLIENT_SECRET' => '0.iSLQ7zzMinac6SbI62onxTdqEYFES1LXoI4paRFFz74.4yFz4Pr3BMIccXgQOb3Ea_FNG2Y' + )); + .. etc etc NetellerAPI Class ============================================ From c5d56fe798f88f265d648786cd0386cca9300468 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 13:55:27 +0200 Subject: [PATCH 13/16] Reflect NetellerAPI namespace in documentation --- README.md | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bc148ad..54ccc62 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Example: Alternatively, you may pass these required parameters to the constructor of each method instead: - $deposit = new RequestPayment(array( + $deposit = new NetellerAPI\RequestPayment(array( 'NETELLER_BASE_URL' => 'https://test.api.neteller.com/', 'NETELLER_CLIENT_ID' => 'AAABTAiQ9pKruN2Z', 'NETELLER_CLIENT_SECRET' => '0.iSLQ7zzMinac6SbI62onxTdqEYFES1LXoI4paRFFz74.4yFz4Pr3BMIccXgQOb3Ea_FNG2Y' @@ -83,7 +83,7 @@ Example ------- - $api = new NetellerAPI(); + $api = new NetellerAPI\NetellerAPI(); $ip = $api->getIP(); var_dump($ip); @@ -91,7 +91,7 @@ Example It can also be used in the context of a child class: - $deposit = new RequestPayment(); + $deposit = new NetellerAPI\RequestPayment(); $deposit->setPaymentMethodValue('netellertest_USD@neteller.com') ->setVerificationCode(270955) ->setTransactionMerchantRefId('adfiu1i23478172349a') @@ -125,7 +125,7 @@ Example ------- - $deposit = new RequestPayment(); + $deposit = new NetellerAPI\RequestPayment(); $deposit->setPaymentMethodValue('netellertest_USD@neteller.com') ->setVerificationCode(270955) ->setTransactionMerchantRefId('adfiu1i23478172349a') @@ -156,7 +156,7 @@ Example ------- - $withdrawal = new CreatePayment(); + $withdrawal = new NetellerAPI\CreatePayment(); $withdrawal->setPayeeProfileEmail('netellertest_USD@neteller.com') ->setTransactionAmount(1234) ->setTransactionCurrency('USD') @@ -184,7 +184,7 @@ Example ------- - $lookup = new LookupPayment(); + $lookup = new NetellerAPI\LookupPayment(); $lookup->setTransactionId('850430740226289') ->setExpand('customer'); $result = $lookup->doRequest(); @@ -231,7 +231,7 @@ Example ------- - $order = new CreateOrder(); + $order = new NetellerAPI\CreateOrder(); $order->setOrderMerchantRefId('adfiu1i23478172349o1') ->setOrderTotalAmount(2099) ->setOrderCurrency('USD') @@ -307,7 +307,7 @@ Example ------- - $lookup = new LookupOrder(); + $lookup = new NetellerAPI\LookupOrder(); $lookup->setOrderId("ORD_1f21ca9d-e647-46bc-9dde-91c70632e587"); $result = $lookup->doRequest(); var_dump($result); @@ -330,7 +330,7 @@ Example ------- - $lookup = new LookupOrderInvoice(); + $lookup = new NetellerAPI\LookupOrderInvoice(); $lookup->setOrderId("ORD_5c0023d3-c928-4771-9016-1fc169283b0f") ->setExpand("customer,order"); $result = $lookup->doRequest(); @@ -372,7 +372,7 @@ Example ------- - $signup = new CreateCustomer(); + $signup = new NetellerAPI\CreateCustomer(); $signup->setEmail("john.smith@example.com") ->setFirstName("John") ->setLastName("Smith") @@ -419,7 +419,7 @@ Example ------- - $lookup = new LookupCustomer(); + $lookup = new NetellerAPI\LookupCustomer(); $lookup->setCustomerId("453523712313") ->setRefreshToken("0.AgAAAU0yy4sHAAAAB1jwsOC9J7TBAYynTble-g2fdC-d.7xIAyXxQWsDaiLzjY4qimsqfyYU"); $result = $lookup->doRequest(); @@ -448,7 +448,7 @@ Example ------- - $plan = new CreatePlan(); + $plan = new NetellerAPI\CreatePlan(); $plan->setPlanId("MONTHLYGREENPLAN") ->setPlanName("Sample Premier Monthly Membership") ->setInterval(3) @@ -476,7 +476,7 @@ Example ------- - $lookup = new LookupPlan(); + $lookup = new NetellerAPI\LookupPlan(); $lookup->setPlanId("MONTHLYGREENPLAN"); $result = $lookup->doRequest(); var_dump($result); @@ -498,7 +498,7 @@ Example ------- - $plan = new CancelPlan(); + $plan = new NetellerAPI\CancelPlan(); $plan->setPlanId("MONTHLYGREENPLAN"); $result = $plan->doRequest(); var_dump($result); @@ -520,7 +520,7 @@ Example ------- - $plan = new DeletePlan(); + $plan = new NetellerAPI\DeletePlan(); $plan->setPlanId("MONTHLYGREENPLAN"); $result = $plan->doRequest(); var_dump($result); @@ -543,7 +543,7 @@ Example ------- - $plans = new ListPlans(); + $plans = new NetellerAPI\ListPlans(); $plans->setLimit(10) ->setOffset(0); $result = $plans->doRequest(); @@ -574,7 +574,7 @@ Examples ### Using Authorization code - $subscription = new CreateSubscription(); + $subscription = new NetellerAPI\CreateSubscription(); $subscription->setPlanId("MONTHLYGREENPLAN") ->setAccountProfileEmail("netellertest_USD@neteller.com") ->setStartDate("2015-05-09T00:00:00Z") @@ -588,7 +588,7 @@ Examples ### Using Refresh token - $subscription = new CreateSubscription(); + $subscription = new NetellerAPI\CreateSubscription(); $subscription->setPlanId("MONTHLYGREENPLAN") ->setAccountProfileEmail("netellertest_USD@neteller.com") ->setStartDate("2015-05-09T00:00:00Z") @@ -616,7 +616,7 @@ Example ------- - $lookup = new LookupSubscription(); + $lookup = new NetellerAPI\LookupSubscription(); $lookup->setSubscriptionId("180") ->setExpand("plan,customer"); $result = $lookup->doRequest(); @@ -639,7 +639,7 @@ Example ------- - $subscription = new CancelSubscription(); + $subscription = new NetellerAPI\CancelSubscription(); $subscription->setSubscriptionId("181"); $result = $subscription->doRequest(); var_dump($result); @@ -662,7 +662,7 @@ Example ------- - $subscriptions = new ListSubscriptions(); + $subscriptions = new NetellerAPI\ListSubscriptions(); $subscriptions->setLimit(10) ->setOffset(0); $result = $subscriptions->doRequest(); @@ -687,7 +687,7 @@ Example ------- - $lookup = new LookupSubscriptionInvoice(); + $lookup = new NetellerAPI\LookupSubscriptionInvoice(); $lookup->setSubscriptionId(166) ->setInvoiceNumber(42) ->setExpand("customer, subscription"); @@ -713,7 +713,7 @@ Example ------- - $lookup = new LookupAllSubscriptionInvoices(); + $lookup = new NetellerAPI\LookupAllSubscriptionInvoices(); $lookup->setSubscriptionId(166) ->setLimit(10) ->setOffset(0); @@ -735,11 +735,11 @@ Example ------- - $webhook = new WebhookHandler(); + $webhook = new NetellerAPI\WebhookHandler(); $webhook->handleRequest(); function payment_succeeded($data){ - $api = new NetellerAPI(); + $api = new NetellerAPI\NetellerAPI(); $result = $api->getUrl($data->links[0]->url); //do something with the response here } From 40a37271efb6aafb16ea80799ec3f00be81e051b Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 15:17:29 +0200 Subject: [PATCH 14/16] Improved error handling --- lib/NetellerAPI.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/NetellerAPI.php b/lib/NetellerAPI.php index e2e965f..d9e5761 100644 --- a/lib/NetellerAPI.php +++ b/lib/NetellerAPI.php @@ -11,7 +11,10 @@ class NetellerAPI{ public function __construct(array $opts = array()){ foreach(array('NETELLER_BASE_URL','NETELLER_CLIENT_ID','NETELLER_CLIENT_SECRET') as $constant) { if(! array_key_exists($constant, $opts) || empty($opts[$constant])) { - $opts[$constant] = constant($constant); + if(! defined($constant)) { + throw new Exception("Missing required $constant"); + } + $opts[$constant] = constant($constant); } } $this->setApiCredentials($opts['NETELLER_BASE_URL'], $opts['NETELLER_CLIENT_ID'], $opts['NETELLER_CLIENT_SECRET']); From 20a6f85f0db3d57845a4a1c7fceef5d0ff7d04a3 Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Thu, 14 Jul 2016 15:52:02 +0200 Subject: [PATCH 15/16] Use a classmap instead --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 36dafcc..1a48e67 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,8 @@ "php": ">=5.4.0" }, "autoload": { - "psr-4": { "NetellerAPI\\": "lib" } + "classmap" : [ + "lib/NetellerAPI.php" + ] } } From b7118158fbfa9d58575b4e8de2187a90cc37308c Mon Sep 17 00:00:00 2001 From: Patrick Kuijvenhoven Date: Fri, 24 Jul 2020 10:36:01 +0200 Subject: [PATCH 16/16] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 54ccc62..6d80ba1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -NETELLER REST API PHP Library +**Abandoned, use https://github.com/worldstream-labs/omnipay-paysafe-payment-hub instead** + +~~NETELLER REST API PHP Library~~ ============================= Introduction