public function postReset(Request $request)
 {
     $card_number = $request->input('card_number');
     $sv = new StoredValue();
     $resetResponse = $sv->changePin($card_number);
     if ($resetResponse->getErrorCode() != 0) {
     }
     return response()->json(['pin' => $resetResponse->getCardPin()]);
 }
 private function resetPin()
 {
     $sv = new StoredValue();
     $resetResponse = $sv->changePin($this->card_number);
     if ($resetResponse->getErrorCode() != 0) {
         Log::error('unable to reset pin');
         //discard or retry
     }
     Log::notice('pin after reset while sending purchase mail ' . $resetResponse->getCardPin());
     return $resetResponse->getCardPin();
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(StoredValue $sv)
 {
     $card_num = $this->card_number;
     $pin = Crypt::decrypt($this->pin);
     $checkBalanceResponse = $sv->checkBalance($card_num, $pin);
     if ($checkBalanceResponse->getErrorCode() != 0) {
         //fail the job.
     }
     if ($checkBalanceResponse->getAmount() != $this->card->balance) {
         //fail the job
     }
     $resetResponse = $sv->changePin($card_num);
     if ($resetResponse->getErrorCode() != 0) {
         //retry?
     }
     $pin = $resetResponse->getCardPin();
     Log::info('new pin ' . $pin);
     $this->card->encyrpted_pin = Crypt::encrypt($pin);
     $this->card->status = 'available';
     $this->card->save();
     $this->delete();
 }