Code Monkey home page Code Monkey logo

dwolla-swagger-php's Introduction

Dwolla SDK for PHP

This repository contains the source code for Dwolla's PHP-based SDK as generated by this fork of swagger-codegen, which allows developers to interact with Dwolla's server-side API via a PHP API. Any action that can be performed via an HTTP request can be made using this SDK when executed within a server-side environment.

Note: Temporary PHP 7.4 support was added using these replacements:

  • \$this\->([a-z0-9\_]+) = \$data\["([a-z0-9\_]+)"\]\; into \$this->$1 = \$data\["$2"\] ?? null;

Table of Contents

Getting Started

Installation

To begin using this SDK, you will first need to download it to your machine. We use Packagist to distribute this package, which allows it to be downloaded via Composer.

$ composer require dwolla/dwollaswagger
$ composer install

To use, just require your Composer autoload.php file.

require("../path/to/vendor/autoload.php");

Initialization

Before any API requests can be made, you must first determine which environment you will be using, as well as fetch the application key and secret. To fetch your application key and secret, please visit one of the following links:

Finally, you can create an instance of ApiClient after configuring the username and password values as the application key and secret that you fetched from one of the aforementioned links, respectively.

DwollaSwagger\Configuration::$username = "API_KEY";
DwollaSwagger\Configuration::$password = "API_SECRET";

# For Sandbox
$apiClient = new DwollaSwagger\ApiClient("https://api-sandbox.dwolla.com");

# For Production
$apiClient = new DwollaSwagger\ApiClient("https://api.dwolla.com");

Tokens

Application access tokens are used to authenticate against the API on behalf of an application. Application tokens can be used to access resources in the API that either belong to the application itself (webhooks, events, webhook-subscriptions) or the Dwolla Account that owns the application (accounts, customers, funding-sources, etc.). Application tokens are obtained by using the client_credentials OAuth grant type:

$tokensApi = new DwollaSwagger\TokensApi($apiClient);
$appToken = $tokensApi->token();

Application access tokens are short-lived: 1 hour. They do not include a refresh_token. When it expires, generate a new one using $tokensApi->token().

Making Requests

The Dwolla client provides high-level methods for interacting with the Dwolla API.

High-Level Requests

High-level methods make development easier by embedding information you would typically refer to Dwolla's API reference for in the SDK itself, such as endpoints, request arguments, and response deserialization. DwollaSwagger contains the API module, which allows the user to make requests, as well as models, which are data access objects that the library uses to deserialize responses.

Each model represents the different kinds of requests and responses that can be made with the Dwolla API. View the full list in the models directory.

The following API modules are available:

Setting Headers

You can pass custom headers in your requests as per the schema of the API models. Here is an example of creating a Customer with an Idempotency-Key header.

$customersApi = new DwollaSwagger\CustomersApi($apiClient);

$customer = $customersApi->create([
  "firstName" => "Jane",
  "lastName" => "Merchant",
  "email" => "[email protected]",
  "type" => "receive-only",
  "businessName" => "Jane Corp llc",
  "ipAddress" => "99.99.99.99"
], [
  "Idempotency-Key" => "51a62-3403-11e6-ac61-9e71128cae77"
]);
$customer; # => "https://api-sandbox.dwolla.com/customers/fc451a7a-ae30-4404-aB95-e3553fcd733f"

Responses

Success

# Retrieve an Account by ID
$accountsApi = new DwollaSwagger\AccountsApi($apiClient);
$account = $accountsApi->id("8a2cdc8d-629d-4a24-98ac-40b735229fe2");

# Retrieve a Customer by ID
$customerUrl = 'https://api-sandbox.dwolla.com/customers/07d59716-ef22-4fe6-98e8-f3190233dfb8';
$customersApi = new DwollaSwagger\CustomersApi($apiClient);
$customer = $customersApi->getCustomer($customerUrl);

# Create a customer funding source
$customerUrl = "https://api-sandbox.dwolla.com/customers/AB443D36-3757-44C1-A1B4-29727FB3111C";
$fsApi = new DwollaSwagger\FundingsourcesApi($apiClient);

$fundingSource = $fsApi->createCustomerFundingSource([
  "routingNumber" => "222222226",
  "accountNumber" => "123456789",
  "bankAccountType" => "checking",
  "name" => "Jane Doe’s Checking"
], $customerUrl);
$fundingSource; # => "https://api-sandbox.dwolla.com/funding-sources/375c6781-2a17-476c-84f7-db7d2f6ffb31"

Errors

You can wrap your requests in a try/catch block to handle errors.

try{
    $new_customer = $customersApi->create([
        //request_body
    ]);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getResponseBody(), "\n";
}

Changelog

  • 1.9.0: Add support for creating bank funding source using a plaidToken for a customer.
  • 1.8.0: Add Exchanges and Exchange Partners API methods.
  • 1.7.1: Fix bug around on-demand authorizations not parsing Dwolla response correctly.
  • 1.7.0: New getCustomerCardToken method added to CustomersAPI for creating a card funding sources token for a customer.
  • 1.6.0: New TokenApi adding support for application access token and client token requests.
  • 1.5.0: API schema updated, CustomersApi updated to add support for email parameter on list customers.
  • 1.4.1: Fix bug in #43 to replace null-coalesce operator with backwards-compatible ternary.
  • 1.4.0: Add temporary support fix for PHP 7.4. Issue #41. (Thanks, @oprypkhantc!)
  • 1.3.0: Add support for custom headers on all requests. (e.g. Idempotency-Key header)
  • 1.2.0: Add KbaApi. See GitHub Releases for more information.
  • 1.1.0: Add LabelsApi, LabelreallocationsApi, and LedgerentriesApi.
  • 1.0.20: Fix previously patched issue with parsing Location header in 201 response in ApiClient.
  • 1.0.19: Patch 201 response in ApiClient.
  • 1.0.18: Patch controller in CreateCustomer model.
  • 1.0.17: Update CustomersApi to update support beneficial owners. Update existing models.
  • 1.0.16: See GitHub Releases for more information.
  • 1.0.15: Optional parameters set to null.
  • 1.0.14: Trim trailing slash from host url on initialization.
  • 1.0.13: Add control over IPV4 and V6 connections.
  • 1.0.12: Update CustomersApi to allow for null limit, offset, and search.
  • 1.0.11: Allow pausing webhook subscription pause; Added support for removed funding source query params; and more.
  • 1.0.10: Patch soft delete to deserialize with FundingSource model.
  • 1.0.9: Add boolean type to fix deserialization
  • 1.0.8: Add balance check endpoint in FundingSourcesApi. Fix transfer failure deserialization in transfer model.
  • 1.0.7: API schema updated, CustomersAPI supports Customer search, new softDelete method in FundingSourcesApi.
  • 1.0.6: Update TransfersApi to include cancel and getting transfer fees. Added some new models and updated some existing models.
  • 1.0.5: API schema error fixed, FundingSource object now has _embedded key to fix serialization issues. Avoid using reserved PHP function names. CustomersApi gets endpoint for IAV verification. Added VerificationToken model.
  • 1.0.3: Added RootApi. Changed auth_token to access_token in compliance with RFC-6749 nomenclature.
  • 1.0.2: New methods added for FundingsourcesApi. More idiomatic response logic for HTTP 201 responses.
  • 1.0.1: API schema updated, new methods in CustomersApi and TransfersApi
  • 1.0.0: Initial release.

Community

Additional Resources

To learn more about Dwolla and how to integrate our product with your application, please consider visiting the following resources and becoming a member of our community!

Credits

This wrapper is semantically generated by a fork of swagger-codegen.

dwolla-swagger-php's People

Contributors

chuchvara avatar cpiggott avatar jasonmead avatar jcoon97 avatar mach-kernel avatar sausman avatar shreyathapa avatar spencerhunter avatar tarricsookdeo avatar therockstorm avatar tpyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dwolla-swagger-php's Issues

ApiClient::deserialize has an unhandled DateTime Exception

In the ApiClient::deserialize the new \DateTime($data); can potentially throw an exception, but it’s not caught in code.

It’s also not documented in the PHPDoc that it could throw an exception, so it’s not caught anywhere throughout the code-base.

What is your protocol here? Catch the exception and give some other date(Doesn't seem like a great idea to me...) or allow the exception be thrown?

ApiClient::L443

Namespace issue with models vs. API call mathod PHPDoc

The namespacing for models is i.e. DwollaSwagger\models\CreateFundingSourceRequest

The class namespace expected by the FundingsourceApi->createCustomerFundingSource is 'DwollaSwagger\CreateFundingSourceRequest'

It looks like maybe at some point all the models were moved into the "models" namespace, but the method PHPdocs were not update to reflect that? As is, the IDE throws a warning, saying:

"expected DwollaSwagger\CreateFundingSourceRequest got DwollaSwagger\models\CreateFundingSourceRequest"

New getAccountFundingSources "removed" parameter

Does not work
$fundingSourceApi->getAccountFundingSources($account_id, false);

Does Work
$fundingSourceApi->getAccountFundingSources($account_id, "false");

I feel like that should be fixed? And be able to accept a primitive boolean since you may be doing it as a variable
$fundingSourceApi->getAccountFundingSources($account_id, $shouldRemove);

Thoughts?

No OAuth

I could not find the code to do an OAuth initiation for Dwolla Direct.

https://docsv2.dwolla.com/#request-user-authorization
Shows to use this code

$OAuth = new Dwolla\OAuth();
$OAuth->settings->client_id = $apiKey;
$OAuth->settings->client_secret = $apiSecret;

$url = $OAuth->genAuthUrl("https://myredirect.com/redirect");

But that seems outdated and part of dwolla-php (API v1)

dwolla-swagger-php has OAuthResponse, but that's it

Any help?

Call to undefined method

When I creating a customer it throw me.
Fatal error: Call to undefined method DwollaSwagger\DocumentsApi::create() in /opt/lampp/htdocs/dwollaswagger/customer.php on line 10

Code I have written
DwollaSwagger\Configuration::$access_token = '';
$apiClient = new DwollaSwagger\ApiClient("https://api-uat.dwolla.com/");
$customersApi = new DwollaSwagger\DocumentsApi($apiClient);

$new_customer = $customersApi->create([
'firstName' => 'Bob',
'lastName' => 'Merchant',
'email' => '[email protected]',
'ipAddress' => '127.0.0.1'
]);

Please help me out to resolve it.

[401] Error connecting to the API (https://api-uat.dwolla.com//customers?limit=10&offset=0)

[401] Error connecting to the API (https://api-uat.dwolla.com//customers?limit=10&offset=0)

This error always came when i tried to feach customer list. below is my code.

DwollaSwagger\Configuration::$access_token = 'token';
$apiClient = new DwollaSwagger\ApiClient("https://api-uat.dwolla.com/");
$customersApi = new DwollaSwagger\CustomersApi($apiClient);
$myCusties = $customersApi->_list(10,0);
print_r($myCusties);exit;

API discrepancy for Transfer Fees

TransfersApi->getFeesBySource($id) converts the response from the API to a TransferListResponse, which expects input of format:

{
  "_links": {},
  "_embedded": {},
  "total": 123
}

However, the response from the API is of this format:

{
  "transactions": [
    {
      "_links": {},
      ...
    }
  ],
  "total": 123
}

This leads to a response that has the correct total, but no fee transfers are being populated.

Call to undefined function create()

The last line produces an error: Fatal error: Call to undefined function create() in C:\inetpub\wwwroot\payments\testing\NewClientsForSandbox.php

Yes: classes are autoloaded at top of page.

`$apiClient = new DwollaSwagger\ApiClient("https://api-uat.dwolla.com/");

$jenny = new DwollaSwagger\CreateCustomer();
$jenny->firstName = 'Jennifer';
$jenny->lastName = 'Smith';
$jenny->email = '[email protected]';
$jenny->phone = '7188675309'

$location = $customersApi.create($jenny);`

Uploading a document - Incomplete function, example missing in docs.

hey folks!
1st of all, thank you for this wonderful well-documented API and SDK. Even a beginner like me could implement it on a Laravel project very easily.

The uploadDocument() function in CustomersApi.php file is missing $body parameter and value for $_header_accept. Also there is no example for this in document.

2021-09-07_22-45

Missing address(object) in Customer.php

static $attributeMap = array( 'first_name' => 'firstName', 'last_name' => 'lastName', 'email' => 'email', 'ip_address' => 'ipAddress', 'type' => 'type', 'address1' => 'address1', 'address2' => 'address2', 'city' => 'city', 'state' => 'state', 'postal_code' => 'postalCode', 'date_of_birth' => 'dateOfBirth', 'ssn' => 'ssn', 'phone' => 'phone', 'business_name' => 'businessName', 'business_type' => 'businessType', 'business_classification' => 'businessClassification', 'ein' => 'ein', 'doing_business_as' => 'doingBusinessAs', 'website' => 'website', 'controller' => 'object' );
https://developers.dwolla.com/resources/business-verified-customer/create-business-verified-customers.html

Deprecated function: Return type

Deprecated function: Return type of DwollaSwagger\models\OAuthResponse::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include() (line 29 of /var/www/html/vendor/dwolla/dwollaswagger/lib/models/OAuthResponse.php).

Error in Step 3 documentation (PHP)

In https://developers.dwolla.com/guides/transfer-money-between-users/03-attach-unverified-bank.html

$new_fs = $fsApi->create_customer_funding_source($customer, array (
  'routingNumber' => '222222226',
  'accountNumber' => '123456789',
  'type' => 'checking',
  'name' => 'Jane Merchant - Checking',
));```

Should read:

```php
$new_fs = $fsApi->createCustomerFundingSource(array (
  'routingNumber' => '222222226',
  'accountNumber' => '123456789',
  'type' => 'checking',
  'name' => 'Jane Merchant - Checking',
), $customer);```

Catching Token Expiration?

Trying to test the implementation of Dwolla SDK for PHP. A common scenario is a token times out and we need to re-auth one. However, we don't know if it's timed out until we make a call to do a particular action (let's say create customer).

Right now it appears your apiClient->callApi function just throws an error when the token is expired, but the consuming function call (CustomersApi->create() ) does not try/catch around this call, and the result is the process just dies out, printing the connection error the output.

What's the workaround for this? Are we missing something obvious? How do you handle token time outs gracefully?

Recommended minimum PHP Version Revision to 5.4.0

I've been looking through the DwollaSwagger API and noticed that there are inconsistencies within the minimum version for PHP and code syntax that is used.

Specifically a few issues I've found are:

Short Array Syntax : This can be seen throughout the application, creating arrays using short syntax example:
[1,2,3,4]
This was not supported until version 5.4.0 of PHP, but is seen throughout the application. PHP 5.4.0 New Features, Short Array Syntax

Function Array Dereferencing : Dereferencing a function array return was not supported until 5.4.0 either but can be seen at in ApiClient:L307 and in other places in the app.
Ex:

$data = !isset(self::http_parse_headers($http_header)["Location"])

PHP 5.4.0 New Features, Function Array Dereferencing

Some Help with Generating Access Token?

Thanks for the SDK, it is a lifesaver.

However, I can't seem to generate a valid access token. I am using the following code since there doesn't appear to be a method to generate through the SDK.

$client_id = '';
$client_secret = '';
$basic_credentials = base64_encode($client_id.':'.$client_secret);
$ch = curl_init('https://sandbox.dwolla.com/oauth/v2/token');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$basic_credentials, 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = json_decode(curl_exec($ch));
$token= $data->access_token;
curl_close($ch);

This does return a token AND the log shows that I DO connect to the API. However when I use that token for Root:

DwollaSwagger\Configuration::$access_token = $token;
$apiClient = new DwollaSwagger\ApiClient("https://api-sandbox.dwolla.com/");
//get root
$rootApi = new DwollaSwagger\RootApi($apiClient);
$root = $rootApi->root();
$accountUrl = $root->_links["account"]->href;

I get the error:
Uncaught InvalidArgumentException: Missing the required parameter $id when calling id in \vendor\dwolla\dwollaswagger\lib\AccountsApi.php:72

If I generate the token through the Sandbox and plug that in. I can get to root and results no problem.

Any help appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.