v7‰PNG
IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ±üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0AºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT
getConfig('client_id')) && strlen($this->getConfig('secret'))
&& strlen($this->getConfig('token')) && strlen($this->getConfig('account_id'));
}
public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
{
if (!($preapproval_id = $invoice->getUser()->data()->get(self::WEPAY_PREAPPROVAL_ID)))
throw new Am_Exception_Paysystem("Stored wepay preapproval id not found");
$tr = new Am_Paysystem_Transaction_WepayOnsite_Checkout_Charge($this, $invoice, $doFirst, $preapproval_id);
$tr->run($result);
}
public function _initSetupForm(Am_Form_Setup $form)
{
$form->addInteger('client_id', array('size' => 20))
->setLabel('Your Client ID#');
$form->addText('secret', array('size' => 20))
->setLabel('Your Client Secret');
$form->addText('token', array('size' => 40))
->setLabel('Your Access Token');
$form->addInteger('account_id', array('size' => 20))
->setLabel('Your Account ID#');
$form->addSelect('fee_payer')->setLabel(___('Who is paying the fee'))
->loadOptions(array(
'payee' => 'the person receiving the money',
'payer' => 'the person paying',
/* 'payee_from_app' => 'if payee is paying for app fee and app is paying for WePay fees'
'payer_from_app' => 'if payer is paying for app fee and the app is paying WePay fees', */
));
$form->addAdvCheckbox("testing")->setLabel("Test Mode Enabled" . "\n" .
"The Test Mode requires a separate developer test account, which can be set up by filling out the following form: https://stage.wepay.com/developer/register");
}
public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result)
{
}
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
{
$trans = new Am_Paysystem_Transaction_WepayOnsite_Checkout_Refund($this, $payment->getInvoice(), $payment->receipt_id, $amount);
$trans->run($result);
}
function getIframeUri()
{
$user = $this->getDi()->userTable->load($this->invoice->user_id);
$invoice = $this->invoice;
$tr = new Am_Paysystem_Transaction_WepayOnsite_GetCheckoutUri($this, $invoice);
$result = new Am_Paysystem_Result();
$tr->run($result);
if (!$tr->getUniqId())
throw new Am_Exception_Paysystem("Could not get iframe from wepay.com - [".$tr->getErrorDescription()."]");
return $tr->getUniqId();
}
// use custom controller
protected function createController(Am_Mvc_Request $request, Am_Mvc_Response $response, array $invokeArgs)
{
return new Am_Mvc_Controller_CreditCard_WepayOnsite($request, $response, $invokeArgs);
}
public function directAction(Am_Mvc_Request $request, Am_Mvc_Response $response, array $invokeArgs)
{
if ($request->getActionName() == 'thanks')
return $this->thanksAction($request, $response, $invokeArgs);
parent::directAction($request, $response, $invokeArgs);
}
public function createTransaction(Am_Mvc_Request $request, Am_Mvc_Response $response, array $invokeArgs)
{
if ($request->get('checkout_id'))
return new Am_Paysystem_Transaction_WepayOnsite_Checkout($this, $request, $response, $invokeArgs);
else
return new Am_Paysystem_Transaction_WepayOnsite_Preapproval($this, $request, $response, $invokeArgs);
}
public function getUpdateCcLink($user)
{
/* if ($user->data()->get(self::WEPAY_PREAPPROVAL_ID))
{
$inv = $this->getDi()->invoiceTable->findFirstBy(array('user_id' => $user->pk(),
'paysys_id' => $this->getId()), 0, 1);
if ($inv)
return $this->getPluginUrl('update');
} */
}
public function getReadme()
{
return <<createHttpRequest(), $doFirst);
$this->request->setHeader("Content-Type", "application/json");
$this->request->setHeader("Authorization", "Bearer " . $this->plugin->getConfig('token'));
$this->request->setBody(json_encode((array) $this->createParams()));
$this->request->setMethod(Am_HttpRequest::METHOD_POST);
$this->request->setUrl(!$this->plugin->getConfig('testing') ?
Am_Paysystem_WepayOnsite::LIVE_URL :
Am_Paysystem_WepayOnsite::SANDBOX_URL);
}
protected function createParams()
{
$params = new stdclass;
$params->account_id = $this->plugin->getConfig('account_id');
$params->fee_payer = $this->plugin->getConfig('fee_payer');
return $params;
}
public function parseResponse()
{
$this->res = json_decode($this->response->getBody(), true);
}
public function validate()
{
if ($this->response->getStatus() != 200)
{
$this->result->setFailed(___('Payment failed'));
return;
}
if (!empty($this->res['error_description']))
{
$this->result->setFailed(___('Payment failed') . '(' . $this->res['error_description'] . ')');
return;
}
$this->result->setSuccess($this);
return true;
}
public function getErrorDescription()
{
return @$this->res['error_description'];
}
}
class Am_Paysystem_Transaction_WepayOnsite_GetCheckoutUri extends Am_Paysystem_Transaction_WepayOnsite
{
public function __construct(Am_Paysystem_Abstract $plugin, Invoice $invoice, $doFirst = true)
{
parent::__construct($plugin, $invoice, $doFirst);
//recurring
if (!is_null($invoice->second_period))
$this->request->setUrl($this->request->getUrl() . "preapproval/create");
else
$this->request->setUrl($this->request->getUrl() . "checkout/create");
}
protected function createParams()
{
$params = parent::createParams();
$params->short_description = $this->invoice->getLineDescription();
$params->reference_id = $this->invoice->public_id;
$params->mode = 'iframe';
$params->redirect_uri = $this->plugin->getReturnUrl();
$params->callback_uri = $this->plugin->getPluginUrl('ipn');
//recurring
if (!is_null($this->invoice->second_period))
{
$params->amount = $this->invoice->second_total;
$params->auto_recur = 'false';
$params->period = 'daily';
$this->uri = 'preapproval_uri';
}
//not recurring
else
{
$params->amount = $this->invoice->first_total;
$params->type = 'GOODS';
$this->uri = 'checkout_uri';
}
return $params;
}
public function getUniqId()
{
return $this->res[$this->uri];
}
public function processValidated()
{
if (!is_null($this->invoice->second_period))
$this->invoice->data()->set(Am_Paysystem_WepayOnsite::WEPAY_PREAPPROVAL_ID, $this->res['preapproval_id'])->update();
else
$this->invoice->data()->set(Am_Paysystem_WepayOnsite::WEPAY_PREAPPROVAL_ID, $this->res['checkout_id'])->update();
}
}
class Am_Mvc_Controller_CreditCard_WepayOnsite extends Am_Mvc_Controller
{
/** @var Am_Paysystem_WepayOnsite */
protected $plugin;
/** @var Invoice */
protected $invoice;
public function setPlugin($plugin)
{
$this->plugin = $plugin;
}
public function setInvoice($invoice)
{
$this->invoice = $invoice;
}
protected function ccError($msg)
{
$this->view->content .= "" . $msg . "";
$url = $this->_request->getRequestUri();
$url .= (strchr($url, '?') ? '&' : '?') . 'id=' . $this->_request->get('id');
$url = Am_Html::escape($url);
$this->view->content .= " " . ___('Return and try again') . "";
$this->view->display('layout.phtml');
exit;
}
public function ccAction()
{
$this->view->title = ___('Payment Info');
$this->view->invoice = $this->invoice;
$this->view->content = $this->view->render('_receipt.phtml');
return $this->displayHostedPage($this->plugin->getCancelUrl());
}
protected function displayHostedPage($cancelUrl)
{
$uri = $this->plugin->getIframeUri();
$popupTitle = json_encode(___('Credit Card Info'));
$this->view->content .= <<