4 * Extension of Better Getter HTTP class specially for the GMO payment
7 class BgetGmo
extends BgetHttp
{
10 * Parsed response data from the GMO server.
12 protected
$gmoResponseData;
15 * Are we using the test server URI?
17 protected
$useSandboxServer = FALSE
;
20 * Get the sandbox server usage value.
23 * TRUE if the test server URI will be used for queries; FALSE otherwise.
25 function getSandboxUsage() {
26 return (bool
)$this->useSandboxServer
;
30 * Set the sandbox server usage value.
32 * If set to TRUE, BgetGmo::getUri() will return a URL for the query test
33 * server IF AND ONLY IF one of the shortcut paths ('EntryTran', 'ExecTran',
34 * 'SearchTrade') are used with setUri().
36 * @see BgetGmo::getUri()
39 * A boolean value representing whether the test server will be for queries;
40 * TRUE if so, FALSE otherwise.
42 * $this, for chaining.
44 function setSandboxUsage($setting) {
45 $this->useSandboxServer
= $setting;
50 * Return the parsed response data from the GMO server.
52 * If a query has executed but the response has not yet been parsed, this
53 * will parse the response.
56 * An array of parsed response data, or NULL if there's no response to
59 function getGmoResponseData() {
60 if (empty($this->gmoResponseData
)) {
61 $response = $this->getResponseBody();
62 if ($response !== NULL
) {
63 // parse_str() is an odd best; a product of the nightmarish days of old
64 // (at least as far as PHP is concerned). As evidence, it needs a
65 // variable passed to it which it will populate with values, sort of
66 // like preg_match(). Why doesn't it just return such an array as its
67 // return value? Good question, because if you use parse_str() without
68 // that second parameter, it creates variables in the global namespace!
69 // I'm sure that was a great idea back in the day when everybody on the
70 // internet was completely, 100% trustworthy (so never).
71 parse_str($response, $this->gmoResponseData
);
74 return $this->gmoResponseData
;
78 * Override the prepareRequest() method to deal with the way that GMO wants
81 * We want to set the POST data as our own built string because if we do it
82 * the normal way, cURL wants to send the data using the multipart/form-data
83 * enctype, which the server does *not* like.
85 function prepareRequest() {
86 // Only go ahead with this if raw post data isn't already being used.
87 if (!$this->getRawPostData()) {
88 $this->setRawPostData(http_build_query($this->getPostFields(), '', '&'));
90 return parent
::prepareRequest();
94 * Override getUri() so that we can provide some handy shortcuts for setting
95 * the URI and change the "real" URI depending on whether we want to return
96 * a URI to the test server or not.
99 $uri = parent
::getUri();
100 if (in_array($uri, array('EntryTran', 'ExecTran', 'SearchTrade'))) {
101 // Note the difference between sandbox and live URLs; sandbox ones start
102 // with pt01, whereas live ones start with p01.
103 if ($this->getSandboxUsage()) {
104 return "http://pt01.mul-pay.jp/payment/{$uri}.idPass";
107 return "http://p01.mul-pay.jp/payment/{$uri}.idPass";