Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for app payment #301

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Payment/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ public function configForPayment($prepayId, $json = true)
return $json ? json_encode($params) : $params;
}

/**
* Generate app payment parameters.
*
* @param string $prepayId
*
* @return array
*/
public function configForAppPayment($prepayId)
{
$params = [
'appid' => $this->merchant->app_id,
'partnerid' => $this->merchant->merchant_id,
'prepayid' => $prepayId,
'noncestr' => uniqid(),
'timestamp' => time(),
'package' => 'Sign=WXPay',
];

$params['sign'] = generate_sign($params, $this->merchant->key);

return $params;
}

/**
* Generate js config for share user address.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/Payment/PaymentPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ public function testConfigForPayment()
$this->assertArrayHasKey('paySign', $array);
}

/**
* test configForAppPayment.
*/
public function testConfigForAppPayment()
{
$payment = $this->getPayment();

$array = $payment->configForAppPayment('prepayId');

$this->assertEquals('wxTestAppId', $array['appid']);
$this->assertEquals('prepayId', $array['prepayid']);
$this->assertEquals('Sign=WXPay', $array['package']);
$this->assertArrayHasKey('timestamp', $array);
$this->assertArrayHasKey('noncestr', $array);
$this->assertArrayHasKey('sign', $array);
}

/**
* test configForShareAddress.
*/
Expand Down