Payum\Paypal\ProHosted\Nvp\Api::doCreateButton PHP Method

doCreateButton() public method

Solution BMCreateButton
public doCreateButton ( array $fields ) : array
$fields array
return array
    public function doCreateButton(array $fields)
    {
        if (false == isset($fields['return'])) {
            if (false == $this->options['return']) {
                throw new RuntimeException('The return must be set either to FormRequest or to options.');
            }
            $fields['return'] = $this->options['return'];
        }
        $fields['paymentaction'] = self::PAYMENTACTION_SALE;
        $fields['cmd'] = self::FORM_CMD;
        $newFields = [];
        $i = 0;
        foreach ($fields as $key => $val) {
            $newFields['L_BUTTONVAR' . $i] = $key . '=' . $val;
            $i++;
        }
        $newFields['METHOD'] = 'BMCreateButton';
        $newFields['BUTTONTYPE'] = 'PAYMENT';
        $newFields['BUTTONCODE'] = 'TOKEN';
        $this->addVersionField($newFields);
        $this->addAuthorizeFields($newFields);
        $response = $this->doRequest($newFields);
        return $response;
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  *
  * @expectedException \Payum\Core\Exception\RuntimeException
  * @expectedExceptionMessage The return must be set either to FormRequest or to options.
  */
 public function throwIfReturnUrlNeitherSetToFormRequestNorToOptions()
 {
     $api = new Api(array('username' => 'a_username', 'password' => 'a_password', 'signature' => 'a_signature', 'business' => 'a_business', 'sandbox' => true), $this->createHttpClientMock(), $this->createHttpMessageFactory());
     $api->doCreateButton([]);
 }