Last active
July 25, 2016 11:31
-
-
Save danmrichards/d81c85cecf0ece13fe4cf72e34241c62 to your computer and use it in GitHub Desktop.
Checksum calculation algorithm for the Softbank payment service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Example checksum calculation for Softbank. | |
*/ | |
// Example only. Real hash key value is provided by Softbank. | |
$hash_key = 'a2d8648d0246a924bed081433930f868c8100224'; | |
// Build out the list of fields. | |
$post_fields = array( | |
'pay_method' => 'credit', | |
'merchant_id' => '99999', | |
'service_id' => '001', | |
'cust_code' => '9999999', | |
'sps_cust_no' => '', | |
'sps_payment_no' => '', | |
'order_id' => '9999999999', | |
'item_id' => '1', | |
'pay_item_id' => '', | |
'itemName' => '', | |
'tax' => '', | |
'amount' => '99999', | |
'pay_type' => '0', | |
'auto_charge_type' => '', | |
'service_type' => '0', | |
'div_settele' => '', | |
'last_charge_month' => '', | |
'camp_type' => '', | |
'tracking_id' => '', | |
'terminal_type' => '0', | |
'successUrl' => 'https://example.com/payment/softbank/success', | |
'cancelUrl' => 'https://example.com/payment/softbank/cancel', | |
'errorUrl' => 'https://example.com/payment/softbank/fail', | |
'pageconUrl' => 'https://example.com/payment/softbank/notify', | |
'free_1' => '', | |
'free_2' => '', | |
'free_3' => '', | |
'free_csv' => '', | |
'request_date' => '20080505175959', | |
'limit_second' => '', | |
); | |
// Concatenate the fields and convert encoding. | |
$post_fields_string = array_reduce($post_fields, function ($carry, $item) { | |
return $carry . mb_convert_encoding($item, 'UTF-8', 'SJIS'); | |
}); | |
// Append the hashkey. | |
$post_fields_string = mb_convert_encoding($post_fields_string . $hash_key, 'UTF-8', 'SJIS'); | |
// Calculate the hash. | |
$sps_hashcode = sha1($post_fields_string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment