Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dercoder committed Jan 15, 2017
1 parent 750fc78 commit a502036
Show file tree
Hide file tree
Showing 37 changed files with 1,659 additions and 0 deletions.
164 changes: 164 additions & 0 deletions src/Gateway.php
@@ -0,0 +1,164 @@
<?php

namespace Omnipay\Skrill;

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Skrill\Message\PurchaseRequest;
use Omnipay\Skrill\Message\CompletePurchaseRequest;
use Omnipay\Skrill\Message\PayoutRequest;
use Omnipay\Skrill\Message\FetchTransactionRequest;

/**
* Class Gateway
* https://www.skrill.com/fileadmin/content/pdf/Skrill_Wallet_Checkout_Guide.pdf
* https://www.skrill.com/fileadmin/content/pdf/Skrill_Automated_Payments_Interface_Guide.pdf
* @package Omnipay\Skrill
*/
class Gateway extends AbstractGateway
{
/**
* @return string
*/
public function getName()
{
return 'Skrill';
}

/**
* @return array
*/
public function getDefaultParameters()
{
return array(
'email' => '',
'password' => '',
'secretWord' => '',
'testMode' => false
);
}

/**
* Get Skrill merchant email.
*
* @return string email
*/
public function getEmail()
{
return $this->getParameter('email');
}

/**
* Set Skrill merchant email.
*
* @param string $value email
*
* @return $this
*/
public function setEmail($value)
{
return $this->setParameter('email', $value);
}

/**
* Get Skrill API password.
*
* @return string password
*/
public function getPassword()
{
return $this->getParameter('password');
}

/**
* Set Skrill API password.
*
* @param string $value password
*
* @return $this
*/
public function setPassword($value)
{
return $this->setParameter('password', $value);
}

/**
* Get Skrill secret word.
*
* • To construct the msid digital signature parameter. This parameter is sent to the return_url if the
* secure return_url option is enabled for your merchant account. This signature is used to verify
* the authenticity of the information sent to the return_url once payment is complete.
*
* • To create the digital signature parameters used to verify the authenticity of the payment status
* information that Skrill sends to the status_url.
*
* • For the email check tool to carry out anti‐fraud checks on email addresses.
*
* @return string merchantEmail
*/
public function getSecretWord()
{
return $this->getParameter('secretWord');
}

/**
* Set Skrill secret word.
*
* • To construct the msid digital signature parameter. This parameter is sent to the return_url if the
* secure return_url option is enabled for your merchant account. This signature is used to verify
* the authenticity of the information sent to the return_url once payment is complete.
*
* • To create the digital signature parameters used to verify the authenticity of the payment status
* information that Skrill sends to the status_url.
*
* • For the email check tool to carry out anti‐fraud checks on email addresses.
*
* @param string $value secretWord
*
* @return $this
*/
public function setSecretWord($value)
{
return $this->setParameter('secretWord', $value);
}

/**
* @param array $parameters
*
* @return AbstractRequest|PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Skrill\Message\PurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return AbstractRequest|CompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Skrill\Message\CompletePurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return AbstractRequest|PayoutRequest
*/
public function payout(array $parameters = array())
{
return $this->createRequest('\Omnipay\Skrill\Message\PayoutRequest', $parameters);
}

/**
* @param array $parameters
*
* @return AbstractRequest|FetchTransactionRequest
*/
public function fetchTransaction(array $parameters = array())
{
return $this->createRequest('\Omnipay\Skrill\Message\FetchTransactionRequest', $parameters);
}
}
94 changes: 94 additions & 0 deletions src/Message/AbstractRequest.php
@@ -0,0 +1,94 @@
<?php

namespace Omnipay\Skrill\Message;

/**
* Class AbstractRequest
* @package Omnipay\Skrill\Message
*/
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
/**
* Get Skrill merchant email.
*
* @return string email
*/
public function getEmail()
{
return $this->getParameter('email');
}

/**
* Set Skrill merchant email.
*
* @param string $value email
*
* @return $this
*/
public function setEmail($value)
{
return $this->setParameter('email', $value);
}

/**
* Get Skrill API password.
*
* @return string password
*/
public function getPassword()
{
return $this->getParameter('password');
}

/**
* Set Skrill API password.
*
* @param string $value password
*
* @return $this
*/
public function setPassword($value)
{
return $this->setParameter('password', $value);
}

/**
* Get Skrill secret word.
*
* • To construct the msid digital signature parameter. This parameter is sent to the return_url if the
* secure return_url option is enabled for your merchant account. This signature is used to verify
* the authenticity of the information sent to the return_url once payment is complete.
*
* • To create the digital signature parameters used to verify the authenticity of the payment status
* information that Skrill sends to the status_url.
*
* • For the email check tool to carry out anti‐fraud checks on email addresses.
*
* @return string merchantEmail
*/
public function getSecretWord()
{
return $this->getParameter('secretWord');
}

/**
* Set Skrill secret word.
*
* • To construct the msid digital signature parameter. This parameter is sent to the return_url if the
* secure return_url option is enabled for your merchant account. This signature is used to verify
* the authenticity of the information sent to the return_url once payment is complete.
*
* • To create the digital signature parameters used to verify the authenticity of the payment status
* information that Skrill sends to the status_url.
*
* • For the email check tool to carry out anti‐fraud checks on email addresses.
*
* @param string $value secretWord
*
* @return $this
*/
public function setSecretWord($value)
{
return $this->setParameter('secretWord', $value);
}
}
58 changes: 58 additions & 0 deletions src/Message/CompletePurchaseRequest.php
@@ -0,0 +1,58 @@
<?php

namespace Omnipay\Skrill\Message;

use Omnipay\Common\Exception\InvalidRequestException;

/**
* Class CompletePurchaseRequest
* Skrill Wallet Integration v7.7
* @package Omnipay\Skrill\Message
*/
class CompletePurchaseRequest extends AbstractRequest
{
/**
* @return array
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('secretWord');
$data = $this->httpRequest->request->all();

if (!$this->hasValidSignature($data)) {
throw new InvalidRequestException('Invalid md5sig.');
}

return $data;
}

/**
* @param array $data
*
* @return CompletePurchaseResponse
*/
public function sendData($data)
{
return new CompletePurchaseResponse($this, $data);
}

/**
* @param array $data
*
* @return bool
*/
public function hasValidSignature($data)
{
$toValidate = array(
$data['merchant_id'],
$data['transaction_id'],
strtoupper(md5($this->getSecretWord())),
$data['mb_amount'],
$data['mb_currency'],
$data['status']
);

return $data['md5sig'] == strtoupper(md5(implode('', $toValidate)));
}
}
76 changes: 76 additions & 0 deletions src/Message/CompletePurchaseResponse.php
@@ -0,0 +1,76 @@
<?php

namespace Omnipay\Skrill\Message;

use Omnipay\Common\Message\AbstractResponse;

/**
* Class CompletePurchaseResponse
* @package Omnipay\Skrill\Message
*/
class CompletePurchaseResponse extends AbstractResponse
{
/**
* @return bool
*/
public function isSuccessful()
{
return $this->getStatus() == '2' ? true : false;
}

/**
* @return bool
*/
public function isPending()
{
return $this->getStatus() == '0' ? true : false;
}

/**
* @return bool
*/
public function isCancelled()
{
return $this->getStatus() == '-1' ? true : false;
}

/**
* @return string
*/
public function getStatus()
{
return isset($this->data['status']) ? $this->data['status'] : null;
}

/**
* @return string
*/
public function getTransactionId()
{
return isset($this->data['transaction_id']) ? $this->data['transaction_id'] : null;
}

/**
* @return string
*/
public function getTransactionReference()
{
return isset($this->data['mb_transaction_id']) ? $this->data['mb_transaction_id'] : null;
}

/**
* @return string
*/
public function getCode()
{
return $this->getStatus();
}

/**
* @return string
*/
public function getMessage()
{
return isset($this->data['failed_reason_code']) ? $this->data['failed_reason_code'] : null;
}
}

0 comments on commit a502036

Please sign in to comment.